I think the best way to avoid the XY problem problem is to give two answers. First, stating the short answer to the assumed question, then the long answer to the explicit question.
So, if somebody asks how they can access private member variables in C++, the first answer would say how to avoid needing to in the first place, and the second answer would say to buckle up because it’s time for the fun world of undefined-but-sometimes-useful behavior.
There was never an XY problem to start with. There is an answer to this question and an answer to that question. Convincing someone to ask a different question is not answering a question, it's mentoring.