I would imagine that once maintenence costs rise significantly, and reliability suffers, airlines think about getting rid of old aircraft. There must be a point when it's simply not worth spending money to keep an aircraft in the air, good money after bad and all that. (A bit like an old car, really.)
There must be much more to airlines' calculations, though. For example, fuel burn compared with newer aircraft, fuel prices, the cost of new/newer aircraft, the availability of credit to purchase these etc., etc.
(Having said that, though, I did wonder whether airlines' phasing out of older 747s had something to do with the TWA crash.)