This completely neglects the opportunity cost of the real estate being used for something else (like housing citizens) instead. Housing is also not fungible - so if you "export" your most desirable real-estate you can't just make more of it.
Take NYC for example. My guess is that at least half of the housing stock in NYC is "pre-war". The "war" in that expression is World War 2. No washer-driers, no elevators, but a good number of mice and rats.
You could absolutely take these buildings down and build back something better. And that better could have more apartment units.
I live in one of the most densely populated neighborhoods in NYC and in the world. All buildings are new (post 2000). If you replace the rest of the city with such buildings, you can certainly have enough housing for 30 million people.
But the foreign investors don't buy to come and live here. You can just build, sell, and not deal with the crowding.
And that could result in lower construction costs too. Why are new apartments so expensive? Because we don't know how to build anymore. We don't know because we don't build.