Buying and owning a house is not free - even if the entire thing had zero upkeep and maintenance. The money spend on the house (lets say 1m) has a cost associated with the foregone interest/income it could have earned you elsewhere (opportunity cost, basically)
Buying a 1m house, even if you borrow no money, costs you a net 50kpa (currently) in foregone, zero-risk interest income from a bank or the government. Them renting it out is just trying to earn a return on that investment (which is just putting upfront capital and hoping to earn more than it costs).
Sometimes they lose (I think housing in many places costs significantly more in interest than rental return right now), but largely they've done well because supply is constrained in most places leading to bidding up of prices. It's just a supply issue - not enough housing for everyone. There's no reason housing can't be both an investment and a place to live - Do you think farmers grow and sell food out of the goodness of their hearts?
Most places make it nigh-impossible to just chuck up a building for people to live in - local governments want permits, you have to provide minimum levels of parking, whatever. Even granny flats will get you in trouble in a lot of places. That's the problem, IMO. In few other fields is it so hard to actually invest in building more of something.
Well-meaning regulations that enforce a minimum standard of housing do have drawbacks as well - eg. minimum 50sqm apartments. It means people that might just want a single room apartment to live in have to buy (or rent) more property than they want or need. I think these make sense for things that are definitely net good (eg. insulation, efficiency standards, etc) for everyone as a whole, but less so when they translate into a oversized housing, excessive parking, and so on - things that add expense that might not be used.