Massachusetts Attorney General Martha Coakley has signed off on the sale of a pair of nonprofit community hospitals, Morton Hospital in Taunton and the bankrupt Quincy Medical Center, to the for-profit hospital chain Steward Health Care System. But Coakley imposed multiple conditions on the deal that are meant to safeguard patients and employees of the financially struggling hospitals. They included a guarantee that Boston-based Steward will not sell either one for at least five years, that it will keep making capital improvements after five years, and that it will continue providing in-hospital psychiatric beds and other services of at least the same scope that the Taunton and Quincy hospitals now offer. If Steward eventually opted to sell the hospitals, potential buyers would be bound by the terms of the conditions, according to the attorney general's office. Last year, Coakley attached similar conditions to Steward's acquisition of Caritas Christi Health Care, a chain of six Catholic community hospitals. That deal, like the Morton and Quincy sales, involved the transfer of organizations classified as public charities to an investor-owned business.