This has specifically been a huge problem in cities with expensive real estate like Los Angeles and San Francisco. It is why the free market approach to fixing the housing crisis doesn't work. The land is so expensive that it doesn't make financial sense to waste it on low margin affordable housing. Developers realize this, snatch up the current options for housing of last resort like SRO buildings, knock them down, and build luxury condos. Supply of the bottom of the market is decreased in favor of supply at the top of the market and this new construction often is less dense than the housing it replaces. People argue that the new supply will eventually trickle down, but that new supply is always snatched up by people moving into the city leaving the people who used live there with no place to go.
There needs to be regulation to force the construction of affordable housing in these markets as the free market has shown it won't be built otherwise.