This is something I think we have to be careful with.
On the one hand, yes, many askers are misguided or confused. Declining to answer their original question, explaining why that question is misguided, explaining what they should be asking instead, and then answering that other question, is often the proper approach.
But on the other hand, telling someone they're asking the wrong question, and refusing to answer the question as asked, can be (and sometimes is) really, really rude. I've lost count of the number of times that:
I've seen askers figuratively pound the table in frustration, insisting that they do really want to do X, begging people to just give them some help doing X, already.
I myself have asked a question about doing something that I know full well is classically a bad idea (or even impossible), explaining that I know this, explaining that I really do have a bizarre need to do the wrong/impossible thing, only to have six regulars skim my question for 1.5 seconds before leaping to the conclusion that I am Yet Another newbie asking that classically misguided question, and launching into patronizing lectures to that effect.
So this is a great example of an area in which, despite our best intentions, we can seem rude and unwelcoming. I would encourage people to be careful with this. Any time you find you're about to do something which is the moral equivalent of saying:
Your question is misguided. You should not want to do X in this situation. You should want to do Y instead. Here is how to do Y.
please stop and think. What if the OP really, truly does want to do X? What if they really, truly have no interest in doing Y? Perhaps, if you have no interest in helping them do X, you should save time and effort by not answering their question at all.
Now, yes, I know. In situation 1 that I described above, if X really is a truly bad idea, it's not important to spare the OP's feelings, sometimes you have to be blunt and tell them the hard truth. But on the other hand, there are lots of beginners who are just not ready to do Y. You, the expert, know with absolute certainty that X is wrong and Y is right, but the beginner's mind is simply not prepared to accept this reality just yet. Sometimes, the road to enlightenment really does involve a detour through X, trying it and watching it fail and learning that it doesn't work. Only then can one accept that Y might be worthy of consideration.
And then there's situation 2. Again, there are plenty of regulars who have an absolutely unassailable faith that X is either wrong or impossible, that no one should ever want to do X. But let's think abut two analogies.
(1) Suppose that, through no fault of my own, I find myself by the side of an isolated mountain road, in the dark, in the rain, with a flat tire on the car. Suppose it's not my car, and I discover that although there's a spare tire, for some reason the jack is missing. And suppose I'm asking for suggestions of what to do in this situation. Do you want to be the person who says
You should not try to change a tire by the side of a mountain road in the rain without a jack. You should always change tires in a clean, well-lit garage, with a smooth floor and proper jacking equipment. Not only is it easier, it's much safer that way.
(2) Suppose it's 1902, and Orville or Wilbur Wright pop up on mechanics.stackexchange.com to ask if anyone has ideas for a lighter but more powerful engine for the aeroplane they're trying to build. Do you want to be the person who says
Heavier-than-air flight is impossible. Why are you trying to fly, anyway? This is an XY problem. You're trying to fly, but what you really want to do is get from point A to point B efficiently. If walking isn't efficient enough, why don't you try riding a bicycle?