You want to do X, and you think Y is the best way of doing so. Instead of asking about X, you ask about Y.
You're trying to do X, and you thought of solution Y. So you're asking about solution Y, without even mentioning X. The problem is, there might be a better solution, but we can't know that unless you describe what X is.
Someone asks how to do Y when they really want to do X. They ask how to do Y because they believe it is the best way to accomplish X. People trying to help go through many iterations of "try this", followed by "that won't work because of". That is, depending on the circumstances, other solutions may be the way to go.
To answer question Y, without understanding larger problem (the context) X, will most likely *not* help them entirely with X.
A.k.a. "premature closure": the questioner wanted to solve some not very clearly stated X, they concluded that Y was a component of a solution, and now they're asking how to implement Y.
The XY problem is when you need to do X, and you think you can use Y to do X, so you ask about how to do Y, when what you really should do is state what your X problem is. There may be a Z solution that is even better than Y, but nobody can suggest it if X is never mentioned.