A federal judge will allow bankrupt Steward Health Care to complete the sales of six Massachusetts hospitals to nonprofit buyers. But the state will have to pay Steward's lenders as much as $5 million more for the deals to close as planned Monday. The early morning ruling resolved a potential snag in the deals amid last-minute squabbling among Steward's creditors. And it capped a turbulent weekend for Steward as it approaches its final hours doing business in Massachusetts. The ruling, by Judge Christopher Lopez, also underscores the soaring public cost of rescuing the company's struggling hospitals. The bailouts could cost the state, the U.S. government, and other hospitals upward of 700 million dollars in coming years.