The first example is grammatical, but, crucially, one can use whether instead of if.
- She asked if we still need a pen.
- She asked whether we still need a pen.
Whether is the Wh-word for embedded yes/no questions.
- Had you gone?
- She didn't know whether/if you had gone.
Yes/no questions merely distinguish two alternatives, so it's easy to substitute a hypothetical if for whether. The important thing is that this is an embedded question complement (acting as the object of ask), and embedded questions require an introductory complementizer (usually a Wh-word, but if is allowed for yes/no embedded questions).
The second example is not grammatical because it doesn't follow the rule for how to embed a question as a complement clause. This doesn't follow the Wh rule; it just embeds the yes/no question as if it were a main clause, with Do-Support and Subject-Auxiliary inversion:
- *She asked do we still need a pen.
This is not good writing style; it's close to a quotation, but not quite:
- She asked "Do you still need a pen?"
uses second person plural you instead of first person plural we, which is supplied by the reference in the embedded question.
In speech (but not writing), the second example could be grammatical, if it was intoned as a yes/no question, and intended to solicit an answer. It might be reported as
- "She asked do we still need a pen?"
if it expects the addressee to answer the question.
Similar remarks hold for other embedded Wh-questions.