A federal bankruptcy judge formally approved the controversial purchase of more than 5,100 rent-stabilized apartments by an international real estate firm, marking a setback for Mayor Zohran Mamdani who attempted to delay the deal and later win legally binding commitments to address thousands of open housing violations.