This is not site policy; this is Stack Exchange rules – Be nice.
Each and every one of us is required, by the tenets of the Stack Exchange network, to be nice. Being nice means, among other things:
Be welcoming, be patient, and assume good intentions.
It is not welcoming to assume we know better than the user him-or-herself what they want. It does not assume anything good about them to presume that what they have asked, isn’t really what they meant to ask, and that we know what is.
Yes, the very line continues:
Don't expect new users to know all the rules
But those are the rules – our stuff. Yes, new users may not be familiar with the site; as the members here, we are experts on that. And indeed, any given user may not be an expert on the material they’re asking about – that’s why they are asking, and they’re asking us because we are (as a group) subject-matter experts in that topic.
But no one is a subject-matter expert on the anyone’s thoughts and feelings but that person. In short,
We do not know better than the asker themselves what they want
Even new users generally know what they want, and even if they don’t, assuming that we do is a lot. It is very rare that we can be sure that an XY problem even exists, much less be able to tell what it is.
We have good intention, but intention isn’t everything
Yes, we do this because we want to help. We do this because we have a suspicion that there is a deeper question that we could answer, or could answer better, than the question actually asked. And it is very, very tempting to assume that they really meant that question, because we think our answer to that question is so good and helpful.
Moreover, new users, while they do generally know their own wants, don’t know this site. They don’t know its users. They don’t know that the numerous comments that seem to be accusing them of not giving all the information, seem to be demanding they justify their question, are really just ham-handed attempts to help more.
And sometimes we get that way, because we sometimes think a little too highly of answers, and forget that ultimately,
We are here to answer the questions people ask
That is the purpose of this site. Doing anything else is logistics, bureaucracy, or troubleshooting – to allow more and better questions to get more and better answers. The only reason we care about the XY problem at all is because fixing it sometimes allows us to help someone, whose question at face value couldn’t have been answered, or could only be answered with something that wouldn’t actually help.
But no one is a subject-matter expert on the anyone’s thoughts and feelings but that person. In short,
The default must be that the question asked is the question meant to be asked
Remember, we are required, by the definition of the network, the Stack Exchange model, to assume that users have good intent. Mistakes are possible; XY problems are a real thing. But you need substantial evidence to the contrary to question someone’s intent to ask the question they asked: after all, the fact that they asked it is massive evidence that they meant to.
No one on the site is required to justify their interest in a particular question
Comments asking about suspected or possible XY problems therefore should be extremely courteous and careful. Particularly from experienced, established users, or even more so diamond moderators, even a simple question can seem to be a simple sugar-coating on a demand, with the implied threat of closing a question for violation of some policy (remember, new users don’t know those!).
So it doesn’t matter if a question seems stupid to you, if the answer seems useless to you: if the question is answerable, by the definitions of our site, it should be answered, and why it was asked isn’t really relevant.
Now, if a question isn’t answerable, it becomes much more important to ask what related questions that we can answer are also of interest to the user. This is a great time to ask about suspected XY problems. Not necessarily the only time, but we should be very hesitant to do so when a valid question is asked.
XY problems are not, themselves, a reason to close a question
A valid, answerable question can still be an XY problem. In such cases, a good and accurate answer may not actually help the person who asked! Or it could even be a bad idea, an answer that is only good because of the constraints of the question.
In these cases, there are generally two options, depending on whether or not the answer to the question is just not useful to the asker, versus actively harmful.
If the answer is fine, just not useful to the asker – say, the user indicates in comments that it isn’t what they were looking for, and further comments clarify that there’s actually an XY problem going on – then the question should be left alone, the answer upvoted appropriately for being a good answer. The question too, if it’s a good question for someone else, even if it turns out to not really be useful to the original asker.
Then the asker should ask a new question, the one they meant to ask, based on the insights gained from the first. There is no limit on the number of questions one can ask, after all.
If the only way to answer the question is to offer something that is really a bad idea, or is just useless to everyone, not just the person asking, then that is an excellent opportunity for challenging the frame of a question – the advice in that Meta is quite useful for this purpose.
The question should also, perhaps, be edited to allow for better answers without challenging the frame, but whether or not to do this can only be determined on a case-by-case basis. Personally, I strongly feel that it is better to err on the side of not editing a question to change its meaning. Challenging the frame is the better approach: it allows you greater room to detail why, exactly, the sort of solution assumed in the question is not a good idea. That makes the answer more useful than simply eliminating the assumption unaddressed.
Note that the question isn’t closed in either case. That’s because we are dealing with a valid question. The question may not be what the asker meant to ask – but the answer can still be useful. Either because the answer is useful, just not to the asker, or because the answer challenges the frame, which is an excellent way for both the asker and future readers to learn about potential flaws in their assumptions.
There is little cause to worry much about XY problems behind valid questions
If someone finds that the good answers to their valid question, are still leaving them with question, with problems to solve, it is trivial for them to simply recognize that and ask another question. And if they have difficulty determining what they want to ask, they can easily ask that too. There is no real reason to pre-emptively assume there is a problem; generally speaking, users will realize the problem when they see the answers aren’t what they are looking for.
Thus, even when we can courteously and correctly ask about XY problems behind valid questions, there isn’t much to be gained by doing so. Doesn’t mean we can’t or shouldn’t – if it’s courteous, that’s fine – but it’s worth keeping in mind, if you have any doubts about whether or not there’s actually an XY problem, or that you are asking about it courteously, it harms no one to just wait and see.
The FAQ about XY problems is addressed to askers
The “What is an XY problem?” FAQ entry exists as guidance to asking better questions. It’s great advice – for asking good questions. Nowhere in the FAQ is it suggested that the community is expected to respond in any particular way to a suspected XY problem. That is not a part of Stack Exchange policy, or even guidance – Be Nice is.
People asking questions should avoid XY problems. They should read that FAQ entry, should understand what it means to ask about Y rather than X, and they should consider their situation fully and ask about X. There is no argument there.
But we have to act in good faith ourselves, as well as assuming it in others. That means, unless we are given evidence to the contrary, we have to assume that users have done what they should, and are asking their question in the best possible way to get the answers they need. To assume otherwise is disrespectful in the extreme, and flies flagrantly in the face of Be Nice policy.