Racism absolutely played a role in how it went down, as did government policy. But the invention of the modern suburb grew directly out of the events of WW2 making it possible for the US to rapidly build large numbers of homes.
People moved away from urban centers because they believed (correctly) that living in dense cities detrimentally impacted their health. This later accelerated in part because of racial reasons.
Housing demand could have easily been met (and was met in Asia and Europe) by building denser urban structures, which is what you would expect to happen if there was a confluence of housing demand, increased wealth, and a general interest in living in cities. There was no interest in the latter, which is why suburbanization took place.
The current urban migration is basically a reversal to the mean and should be beneficial in the long term.