Under what conditions do airliners retire aircraft and sell them to other airlines?
Some reasons for an airline to sell some of its fleet:


they need quick cash (as ratchet freak points out). This usually means the company is in serious trouble
they're changing their route network and there's no more need for it (e.g. KLM dropped a lot of very short flights in the 1990s and early 2000s, and got rid of the aircraft that were operating them as they were inappropriate for the longer routes that replaced them)
they bought out another airline and have no need for (all) its aircraft, or want to replace them with other types to keep their fleet homogenous (operating many similar types is less economical than operating a smaller number of types)
they're splitting part of their operations to a new company set up for the purpose (the new company becoming the new owner of the aircraft, usually for a symbolic fee), for example a regional affiliate or a charter operation
it may be more economical to replace the aircraft then to keep them. When NWA decided to replace their DC9 fleet with A320s this was for economic reasons (lower maintenance and fuel cost for example), not because the aircraft had run out of fatigue life. The aircraft were old so most probably were scrapped, but some may well have ended up with airlines in other countries, replacing even older aircraft or expanding existing DC9 fleets there.
and some airlines just want to portray a public image of always flying shiny new aircraft. I believe Singapore Airlines used to have a policy like that and replace everything it bought relatively quickly (more so than most other airlines at least). PanAm was like that as well. If you have a reputation of exclusivity, this may add to customers' willingness to pay premium to fly with you