Some people stay in a job for 15-20 years. They are a programmer for maybe 10 of those, but over time they grow into a niche, the company grows, and that becomes a job title.
Maybe they get called a project manager, or a product owner, head of QA or engineering or lead architect. Either way they aren't a programmer any more and they mostly manage something instead of doing - manage people, contracts, processes, customers...
And that's why programming has a pay ceiling - careerist programmers become something else, and footloose programmers become consultants and contractors and leave the regular pay figures.
The value of a good programmer probably becomes diminishing returns after a certain point. The best programmer in the world can't raise the sales of your web app past a point - if they do what it takes to do that they become something else, like a product manager. That point depends on the technical difficulty of the task and the size of the opportunity, but most code needs a good coder, not a great one, and beyond that it's all product fit, sales and luck.
I'm footloose too, and I'm noticing as I get older that the people interviewing me have often been in their job a long time. They bet on the company and became less flexible in the general labor market in return for better opportunities internally.
Honestly, when I work for them, I'm usually surprised how many normal things they don't know. Maybe they've never seen proper unit testing, or don't know what ITIL is, or think linux is still an immature product and you should stay safe with a microsoft stack.
But they know why the code is the way it is. They know what was tried in the past, and how it failed. And their boss has seen what they do in a crisis, which is much better than trusting someone unpredictable.
My suggestion to someone young, if you have the temperament, is to stay for up to a decade and grow into a new, higher value role. Then learn that until you know it well enough to get a job elsewhere and move before you stagnate.
A critical problem that exaggerates the "ageism" is people who sit in the same corporation for 15-20 years, get laid off because companies change, and haven't refreshed their skills for many years. I saw my spouse go through this last year. She got laid off from the company where she'd worked in a variety of roles for 13 years. Her field toward the end was product management/ownership, and she liked it, but she didn't like Agile - she'd had bad experiences at her employer with careless engineers using "agile" as an excuse to have no process and no oversight. She had also spent many years developing deep domain experience in a narrow specialty (international e-commerce). She could find generic PM jobs easily enough, but they didn't exercise her domain experience and they didn't want to pay her what she'd been making just to be a generic PM. It took her six months to find a new job that uses her domain expertise (educating herself about Agile along the way).
For people less determined and hardworking than her, the problem can easily be much worse. If you've done nothing but Microfocus Cobol for the past 20 years and suddenly have to find a new job because you employer finally ditched that antique piece of crap, and you aren't interested in learning how to do something modern, you're in a world of hurt.