Most importantly location matters. Space and buildings are not something that you can easily ship from one market to another to balance supply and demand. Space is inherently limited and replacing existing buildings with new more efficient ones is also problematic when you have people happily living in those old buildings, especially in high demand areas. Construction work takes time and in the meanwhile the displaced families will create even more demand.
There are practical limits on how densely you can pack floor space before it becomes prohibitively expensive, unsafe, or simply impractical. As you build higher the costs grow exponentially while the livable space per floor keeps decreasing due to the tapered shape of the building and need for larger structural core and more elevators. Above certain height you will be forced to target wealthier residents which means either offices or large luxury apartments that are anything but space efficient.
Construction is extremely capital intensive. A building takes a large upfront investment, and it takes a long time for it to pay off. With cars the cost of making more is marginal once you have an assembly line in place so it's significantly easier to re-invest profits into ramping up production.
Renting real estate makes more sense than renting automobiles because real estate is more expensive, less liquid, and better at holding its value over time. Owning a house is more difficult even when it would make financial sense to do so (not everyone can get a mortgage, or commit to living in the same city for an extended period of time).
> for better or worse we have chosen to place almost no limits on the quantity and density of cars
Even worse, most places have chosen to place a lower limit on the quantity and density of cars through parking mandates. It is absolutely insane that we are still wasting space on parking even in densely populated urban centers where it's impossible to accommodate everyone commuting by car.