If you know the answer to someone's question, and you want to be helpful and informative, then simply answer it. Follow your answer with "why do you need this btw? there might be a better approach" when appropriate. This is Example 1 from the OP. It's great!
If you can't answer a question then the most helpful thing to do is usually to stay silent. This is where the XY problem problem strikes: know-it-alls who need to have an answer for every question, who have nothing to say but still need to be heard.