If investing in housing is made less profitable, there will be less investing and consequently less supply in the long run, thus making the housing problem worse.
Investment in housing (ie actively rented places) are unaffected, so there is no reason there woukd be less investing on that front
See for example:
https://m.murciatoday.com/almost_half_a_million_vacant_new_b...
https://www.investigate-europe.eu/en/posts/the-empty-house-a...
It isn't a particularly Spanish problem either: following article about the American version of it
https://www.cbsnews.com/news/empty-office-buildings-doom-loo...