Building less in those areas certainly would not help. But it's also unlikely that enough can be built to preserve space for all existing residents in any realistic time-frame without subsidies and active efforts (which some cities do better than others).
As for why booming areas don't build enough: exclusionary zoning, burdensome processes, NIMBYism in local meetings, and learned government helplessness.
Things like redlining are no longer legal, but the desire by people to exclude people that they do not want their kids to end up like remains. One legal way to do this is to make the cost of living sufficiently high that it guarantees your neighbors conform sufficiently to society's standards that they were able to accumulate wealth.
Here's a podcast episode on the particular issue if anyone wants to explore more
https://www.strongtowns.org/journal/2024/3/18/benjamin-herol...
What's happening is two things 1) that people in detached homes in the middle of town the who aren't willing to live in apartments are seeing costs go up (because their land is more valuable) and 2) more people from the town are working it the city.
Of these two thing, I'd say that #2 is generally bad, but also orthogonal to building apartments. It just happens to be that they often happen together.
The only ways to prevent this would be deliberately trash the neighbourhood to make it unappealing, or a hukou system like china