Could also be a bell curve situation - e.g. you have a class where the
average locomotive lasts thirty years, but some last fifteen/twenty years whilst others last forty/forty five years - that kind of deviation may be expected (rather than everything lasting
precisely thirty years)
As
@thedbdiboy says above, some classes took a long time to be built (which means that, even if the standards didn't change during that time, there may be some that are several years older than others - the 170s were built over seven years - a longer period if you include the 168s - so I wouldn't expect them all to be withdrawn in the same year)
Some stock is built to meet a need today (e.g. we need x number of locomotives/ units to perform a current role), but as they are cascaded onto "secondary" routes over the years, fewer and fewer are required in regular service, so you don't need so many, which means that there's no urgency to repair every bump/scratch/ bit that falls off... sometimes the loss of a key freight contract will mean significantly fewer locos required so some scrapped before their time (e.g. the 58s may have been built with the expectation of many years of coal but when that dried up the locos weren't required
Then. at mid life, the fact that a class of locomotives/ units are no longer being produced means that it's simpler to "borrow" a working part from an unused machine, which means the depot has a "Christmas Tree" which donates its windscreen wipers etc to locomotives/units in need of replacement ones...
You might keep a number of locomotives/ units sat in a yard without being used (as the work dries up for that kind of train), which is fine for a while - dump them in a pile at Toton etc - but then things need an overhaul/ passing an "exam" etc to tick a box and a decision needs to be taken whether to spend money on it to keep it going or give up on it, so some things will get scrapped before their time, because it's not economic to keep them - same goes for accident damaged stuff - you might justify a new fuel tank for something ten years old but not at twenty years old
So, to take the example of the 170s, private TOCs ordered enough to meet the PVR on certain routes - now that they are around twenty years old, they have been replaced on some routes either by electrification (e.g. Edinburgh - Glasgow, Rugely - Birmingham) or by a cascade of more suitable stock (e.g. Hull - London), some of the routes that they were ordered for don't exist (e.g. Barnsley/ Matlock/ Burton no longer have London services) - some of them have been cascaded onto services that they're not really suited to (e.g. Harrogate stoppers) - if one is in an accident today then I guess it'd be worth repairing it but there'll come a time when it'd be dumped in a siding at Tyseley and was slowly robbed of parts (because it's simpler to pinch components than order new parts, especially a one-off) - then as the 170s run out of "flagship" routes to operate they'll move onto services where they can do an okay job but probably won't require so many to run them - so they might not have any money spent on them to meet exam requirements (since there are a surplus of such units) - the class will dwindle down from hundreds to dozens
Then again, I guess there's a risk that something might be withdrawn en-masse if a safety critical fault is found or a route is closed (e.g. the 76/77s didn't hang around after Woodhead, for obvious reasons)