@ONpI9YE-hoq
If you are in the right place at the right time, you can be a grey hair at a very cushy job.
If you own some God-awful complicated piece of code (scripts/build processes that no one understands or have little time and patience to reverse engineer), you could rule and collect a fat paycheck. Is this the institutional knowledge/domain knowledge you were inquiring about? You have to be more a politician and less an engineer to get there. The majority of grey hair I have seen are in this category.
You also suffer from observational bias. For every 1 grey hair you see around, you won't see the 10 others who were let go.
The bitter truth about software engineering is that the best software engineer would make himself/herself redundant from a specific domain. A lot of times, this happens (to the entire field taken in aggregation; the newest open source development focussed on automation tells us that).
Unless you are learning constantly, you always face the danger to be obsoleted. Unfortunately, the human brain slows down...and 40 seems to be that magic biological cutoff number. You think the corporate fatcats don't know this? Not only you are slow at learning, you need far more salary and more time off to attend to those pesky people you call children and spouse at home. Please!!!!!
These are some bitter pills I have swallowed as I approached near 40 as a software engineer. I have always moved aggressively (Cisco was a short-gap stop to me and unfortunately, I got stuck at babying legacy code...a couple of years wasted in my life, but I enjoyed the paycheck). I have saved like crazy, am near paying off my mortgage already and have been maxing out my retirement. Who knows? I might actually welcome an LR at 45+.