To answer your second question, when aircraft are being sold it is common practice to perform a check ride in which the plane is put through a series of less-than-normal flight maneuvers that would reveal possible signs of impending maintenance and/or damage. This (AFAIK) is not a requirement, but rather a good business practice.
To answer your first question (poorly), it most likely depends on airline policies. Aircraft that are not fit for flight are simply not fit for flight, however airline policies, and/or the economics of retaining specific aircraft may contribute to the sale of airliners. An additional factor may be fluctuations in demand for certain routes, in which cases certain types of aircraft may become less feasible to own (turboprops are more economiceconomical for shorter routes, turbojetsjets are better for longer routes).
Airlines also engage in the practice of loaning aircraft to other airlines.