The answer to the question is as varied as the chicken keeper. You do what is right for your family.
Things of course to consider are the feed costs, room, and health concerns of aging hens.
If you are needing the eggs, obviously non-productive hens are draining the feed bucket but not producing. Grain gets expensive, so those that aren't producing are literally burning feed dollars. I refresh the flock each year by always having various ages....new chicks, grow outs, current layers.
I find that I can Craigslist fairly easy my 2 to 3 year old hens. We have eaten our roosters, but I'm not a big fan of an aged layer. They are only good for stewing and it always comes out tasting a bit gamey for me with the old hens. So, I Craigslist or give away to fellow chicken friends.
My brooding hens get royal treatment for longer as they are useful as good brooders. But if they stop being a good brooder, they go.
Only 1 or 2 very special birds get to stay as long term pets, but I've phased out most of those for reasons number 2 and 3.
Room. The more crowded your conditions, the more stress you place on your grounds. All those tramping and scratching feet do damage to grass and plants. They definitely produce some wonderful compost, but also a fair amount of fecal material. In time, worm and coccidia loads begin to build up. If you can't rotate fields (ideal), then you have to refresh top soil/bark and watch your numbers or deal with a lot of medicines to be treating the resulting issues. (Unfortunately, my wet Oregon winters don't kill the bugs in the soil like the colder zones do).
Age. Sadly I find as my hens age so do their immune systems. It is my older hens that become vectors of illness for my younger hens. The older ones begin to get a build up of internal and external parasites that the younger ones simply don't have, even though I treat everyone the same with meds and applications. And it is generally the older ones that catch the virus going around. Another reason I find to keep my flock younger.
So as I have a smaller area to work with (1/3 acre of which the house has to also sit), I have to consider long term conditions of my land and overall health of the flock for sustainability.
If I had more room, I could be a bit more lenient, but again, grain is expensive, birds age, and I can only keep so many "pets." If they aren't helping to produce eggs to sell that purchase their grain or furthering the flock's overall health and productivity, then they have to go.
Just what I do.
LofMc