Yeah ageism wasn't always part of our profession. It was probably a side effect of rapid progress combined with the desire for wage suppression. It has let us move faster as old bad ideas lose their champions faster, but we then lose all the old good ideas too. Not every developer should turn into a manager. We don't need that many managers, and good managers are more rare than good developers in my experience. Having a stereotype that old developers that aren't rich yet must be bad developers comes and goes as the bubbles form and burst. If you develop in a domain where developers need lots of on the job expertise before being productive, or in embedded or game development where a big part of TC is job enjoyment, then that stereotype is already stale and career staff developers can regularly be geniuses.
On the other hand people smart enough to be engineers are smart enough to be in management so if that is your interest the world has a lot of people who for whatever reason can't won't do management. While managing other engineers is a way in, once you are in management you can do run a factory or a construction site and those often are places where workers cannot break into management.
There are a lot of different types of intelligence. I have met many brilliant developers that made horrible managers. And I have met many developers that we joked they moved to management to protect the codebase, that turned out to be great managers. That is a good point though, that many jobs don't have paths into managing those same jobs.