Because we stopped making buildings to create shelter, or livable places. The process became industrialized, and serves the same goal as most processes in a capitalist society: to generate most profit at minimum cost.
Even though today we build things with minimum cost, there's still not enough housing for everyone. There's a housing crisis in every major North American city, caused in large part by lack of affordable homes (and no, not everyone can work remotely from Quaint Townville, Wherever -- in fact, most can't).
It does not cost a million dollars to build a single detached house. Closer to a quarter million for materials and labour, give or take the cost of land. Profit for the seller is what makes up bulk of the cost. Profit margin for the builder. Decades of steady profit for the bank that sells and services the loan. The purpose of housing has become to be an investment vehicle, not shelter.
We could easily afford to build and maintain enough housing for everyone. Create and sustain vibrant communities where people's basic need of shelter are met. But it's just not compatible with the capitalist mindset.