It's frequently NOT an honest effort to help. It's just "well that's a stupid question, let me show you how I know more..."
When you really are trying to help and you think it's an XY you can answer politely by actually answering their question and then saying "but you may want to do this instead". Try it.
Indeed, a good answer to X will make clear why Y is the better option in most cases. But its a thin line to tread between subtly implying that X is bad, and saying "only idiots do X, anyway here's how an idiot would do X".
You suggested that in your previous comment, and I explained already why I don't think that's a good idea: it's liable to cause your alternative suggestion to get ignored and proliferate bad practices.
If someone has a genuine desire to help, then they also inherently have an interest in making sure people don't continue down paths which are likely to lead to more problems in the end. Otherwise, you might end up spending more time supporting the follow-on issues created due to the misapplications of your own advice than you spent providing the support in the first place, which would not be an efficient way of helping.
> it's liable to cause your alternative suggestion to get ignored and proliferate bad practices.
I just don't think that is the case. On the rare occasion that somebody has answered like this to me I've just read their answer and thought "oh right that makes more sense I'll do that".
When you really are trying to help and you think it's an XY you can answer politely by actually answering their question and then saying "but you may want to do this instead". Try it.