I have to hang my head in shame because this happened to me. I had a programming test a few weeks back for a senior level position about recursive operations on trees that I absolutely tanked.
That speaks to a lot of issues, actually.
Sometimes it is because the interview questions are bad. I've seen that, I've experienced that, I've had it happen as both the giver and receiver.
And yet... It could be because of other factors.
That story also touches on age discrimination, which is a frustrating thing. Some companies fire people only because they are deemed too old, or because they don't fit in any more, or other age-related reasons. That is a bad thing and should be corrected.
I've worked with one developer who was getting Parkinson's disease. His hands had tremors, but he could still do the job. Ultimately it was not age discrimination that resulted in his termination, and his family was glad he could keep working as long as he did.
I've worked with other developers who were fired in their 40s. One in particular had spent several years focusing only on build systems. When the build system was replaced we tried to put him back on a mainstream team. He asked for tools development, so that was where he went. When he couldn't even handle basic tasks, he was called in and asked "You are not being productive. What can we do to help make you productive? Is there some product or some team or some language or some tool you need?" After several more months it became clear that he had lost the skills he used to have. He may have mastered a specific build tool, but he let all his other skill fade and he became useless once that specific tool was gone. Sadly he was let go not because of his age, but because he was no longer competent in general software development.
Good developers will continue to learn and grow and pick up new skills and talents. This constant growth helps everyone. It helps the company, so many companies encourage it. It helps the individual as they can add the items to their resume and work history.
Sadly, some developers stop learning new things. They stick with the languages and tools they picked up at college and never learn another language unless the company mandates it. I know many C++ developers who were let go in layoffs, chosen in part because they refused to update and learn new things, they balked at additions to the C++ language, they fought code reviews where others were using range-based loops, they refused to accept the need for constant growth.
Others will sadly move on to more and more abstractions until they can no longer work with fundamentals. Like the co-worker described earlier, they'll focus so much on one specific tool and not bother to maintain other skills, soon they become like the buggy whip manufacturers who find themselves exclusively bound to an dying product.
Perhaps it is because I do take some steps to maintain what I have formerly learned, but I do not understand how so many developers allow their skills and knowledge to atrophy.
While you might lose some details and have to address that in an interview (e.g. "Well, with recursion running the risk of blowing the stack or causing similar problems I haven't used it for years, preferring iterative solutions...") a senior developer should still be able to explain the basics and fundamentals tree traversal. For binary trees you can navigate by prefix, infix, or postfix, it may take some moments of reasoning to figure out the details but the basics should still be there.
As an analogue from that list, I haven't worked in SQL for many years but I still know what a primary key and foreign key are and how they work, perhaps because in programming the concept of mapping data from one place to another and indexing from one collection to another is such a common thing. Also on those questions while I have long ago forgotten the magic incantations for the types of joins, I do recall the effects of the joins: they are set operations for an intersection (A&B), all of one side plus the intersection (A+A&B) and the union (A + B). Perhaps when I am old enough that dementia starts settling in I will forget these types of things, but I recall these topics from decades ago. My high school age kids come to me with problems in math, history, geography, and except for a few things that have changed I'm able to explain the concepts these many years later.
If you fall into the unfortunate bin of people who became so specialized that they forgot how to do generalist work, it can make your life very difficult when the inevitable happens. When the layoffs do arrive, how will that person find work in the future?