I spent years on IRC, first getting help and later helping others. I found out myself it was very useful to ask such questions when someone I didn't know asked a somewhat unusual question.
The key is that if you're going to probe for Y, you usually need to be fairly experienced yourself so you can detect the edge cases, where the other person has a good reason.
One approach I usually ended up going for when it appeared the other person wasn't a complete newbie was to first explain that I think they're trying to solve the wrong problem or otherwise going against the flow, and that there's probably some other approach that's much better.
Then I'd follow up with something like "but if you really want to proceed down this rrack, this is how I'd go about it", along with my suggestion.
Yep. The magic question is "what are you trying to accomplish?". Oftentimes people lacking experience think they know the best way to get the results they're after and aren't aware of the more efficient ways someone with more experience might go about solving their problem.
Except that SO has a crystal clear policy that the answer to questions should be helpful for everybody reaching it through search, not only the person asking it. And that questions should never be asked twice.
So if by chance, after all this dance the person asking the question actually needs the answer to a different question, you'll just answer it with some completely unrelated information and that will the the mandatory correct answer for everybody that has the original problem for any reason.
I don't think your analogy really helps here, it's not a question. If the question was "How do I get to the top of the mountain" or "How do I want to get to the top of the mountain without hiking" the answer to both would be "Gondola".
I see it all the time professionally too. People ask "how do I do X" and I tell them. Then later on I find out that the reason they're asking is because they went down a whole rabbit hole they didn't need to go down.
The truth is sometimes people decide what the solution looks like and then ask for help implementing that solution. But the solution they chose was often the wrong solution to begin with.