Potentially precedent-setting ruling could affect hundreds of buildings, giving municipalities broad power to demand costly renovations at owners’ expense.