Such a law existed in San Francisco since 2022 and it was just cancelled by court order. The problem is: there are so many edge cases for empty apartments that it is impossible to account for. In Berlin, e.g., just imagine all the empty apartments in 10 years because no one wants to rent unrenovated, uninsulated apartments because of energy prices. The landlord cannot pay renovation. Forcing landlords to pay an empty apartment penalty doesn't help here.