TL;DR: because managers want to know if they can offer you what you want.
I stumbled upon a discussion on Twitter yesterday, where someone was saying they're surprised that asking "Where do you see yourself in 5 years?" is still a thing. I have been asked this question before, and now I'm asking it as a hiring manager in my interviews. This is a short post about why.
I remember my first couple of interviews as a software engineer: just starting my career, I obviously had no idea where I'll end up in 5 years. It might be that in 6 months I'll find out frontend development is not my thing, and will switch to mobile/embedded/the next big topic! Maybe I'll be an engineer at Google, maybe I'll be a project manager (I kind of am now, which is funny). I had to say at least something to the question, even though I wasn't sure what the future will hold, so I said something in lines of "Development sounds very exciting!". After the interview, I would talk to someone and wonder why this question is being asked at all at such an early stage of my career.
Now that I'm a manager and I want to hire an engineer to join my team, I think about this question differently, and I try to formulate it in a clearer form, like "What would you like to be doing in the next couple of years?". This way, I get to learn more about a person's:
and this information helps me evaluate if we can offer the opportunities a person is looking for.
"But what if I don't know what I want I'll be doing so far into the future?" — that is also fine. Just speak about a period you have plans for, or talk about overall directions you're currently considering for yourself. An interview is a discussion, not a monologue, and everyone understands that plans for the future can be vague and may change.
Hope this helps!