I suspect it would make more sense to do so via tax policy, i.e. high property taxes (or LVT) with a deduction for each occupant.
> why would the government have any right to tell me what to do with my building?
For one thing, governments have a vested interest in not being overthrown. If a sufficiently large percentage of the population believes that their living standards are declining (including not having a place to live) then an increasing number of people will arrive at the conclusion that revolution or terrorism has a positive risk/reward ratio.
I've worked in a country where the previous government had allowed this to occur; apparently it happened gradually and then suddenly. Beyond a certain point you can only consider something "my building" if you have the means to defend it against anyone who might wish to make it their building. In that case, the possession of a piece of paper which you once used to outsource the enforcement of your property rights to the previous government isn't very useful.
(Edit: To be clear, I think allowing squatting is a poor solution to the problem of reducing homelessness and better tax and housing policies are more sustainable and equitable, I'm just explaining why the government has a substantial interest in what private landowners do with their properties.)