It's also common on Stack Overflow, but at least there, others will answer the actual question you're asking.
I feel like this is one example of a general second guessing phenomenon. Sometimes that second guessing is accurate and sometimes it makes too many assumptions about the other person, or otherwise fails to consider other explanations for their behavior.
I left a project once because the sponsor wasn’t letting us interact with the real customer to find the real need. That path only leads to doom and despair.
It is also not an appropriate framework for a responder to follow, only for an asker to think about what they should be asking. And far far far too many people read it and take away from it a belief that they need to find out the real reason a person is asking a question before answering.
When a person asks a question, you do not need to understand why they are asking it. It does not matter that you cannot guess why they want to do or know something. Assuming and digging for an XY problem is just looking for an excuse to not answer the question.
If the question has an answer and you know the answer, answer it and be done. The knowledge is valuable even for its own sake. If not to the person asking, then to someone else who has the same question for another reason. If you want to probe further, do it after answering the question.
Because, goddamn, if you think it's annoying to be asked about something that you think is the wrong thing to do, it's really fucking annoying for someone to demand to know your backstory before deigning to answer a question as asked.
A good example of an XY problem is people asking where to buy a suicide cord. Is the helpful answer to show them how to make one, or to hint at the fact that it's called a suicide cord?
If you desperately want to shoot yourself in the foot, don't mind people asking why you want to borrow their gun.
You create a false dilemma. The helpful answer is the one that answers the question, and if you also want to suggest alternatives, feel free to do more than answering the question, but don't just question their motives instead of answering, because questioning someone's motives instead of answering is an antagonistic behavior. You're basically saying "I don't also want that thing, therefore you must be an idiot." That's an obnoxious framework to operate under.
It's a gross idealization that every problem can be directly solved, or is "shovel ready." In my world there are often oodles of blockers, dependencies, and preparations that have to be put in place to even start to solve X. Asking about Y and Z along the way? Par for the course.