My take is that real estate sold to foreigners is the best kind of export. You sell the good to the foreign investor, but the good stays in place. From time to time that investor visits and drops money in the local economy. Most of the time the guy is not there, but pays taxes. Pays taxes but does not consume government services.
Actually you can. It's called building.
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.