I think that most of the time, when question askers are aware that they are not using the best tool for the job, they explain why not. And so it's tempting to generalize and assume that when they do not explain why, they aren't aware -- or just haven't put enough effort into the question.
However, given recent introspection across the stack exchange community about creating more welcoming environments, I think that it's important to assume a certain level of background knowledge until the asker directly requests more information.
Striking a balance
My personal tendency is to answer the question as asked, because that's just how my mind works. I've been stung a couple of times as a result -- and that's probably a good thing. It is important that a site like this point out the potential pitfalls of a particular approach, and I've learned to read questions with a slightly more critical eye over time. I still generally answer the question as asked, but if I foresee a problem, I may add a caveat, or suggestion that the asker consider a different approach.
But when doing so, I do my best to remain aware of my own ignorance. It's often impossible to convey all of the relevant contextual details behind a particular question. It's unreasonable to expect askers to cover every possible source of confusion. And there are very few "bad" approaches that are truly bad in every imaginable context. Taking a moment to acknowledge that you don't know everything about the asker's situation shows respect, and actually makes it more likely that they will consider your advice, even if they conclude that it doesn't apply to them.
Thinking about the long term
When I first answered this question -- quite a long time ago, -- I ended with this statement:
More generally, I'd say that on balance, I'd rather have a site that is a bit pedantic at times than have a site that encourages the proliferation of bugs!
My position has changed because I see more clearly how this kind of pedantry works to exclude and belittle some audiences. And the notion that pedantry might somehow save us from a world full of software bugs seems quaint and romantic to me now.
These days, I would rather someone use the wrong tool today and come back tomorrow than use the right tool and never return. In the long run, we'll get a lot more good work done.