Whose time was wasted? For the asker, the exploration of Y and the eventual realization that it is not a good way to pursue X is a learning experience with value. For the answerer, they may feel their time is wasted if the goal is to answer questions. But if the goal is to help the asker deepen their understanding then the discussion of Y isn't wasted time at all.
This presupposes two things: 1. The asker must have the curiosity and humility to interrogate Y as their chosen method to reach X. 2. The answerer must set aside their ego in order to provide genuine help instead of patronizing advice.
The question/answer format of Stack Overflow does not lend itself to curious exploration of questions and I think the gamification aspect rewards egotistical answerers. I say this despite deriving a lot of value from SO over the years.