In Bereishit Raba (38:6), a number of differences are identified between the generation of Noaḥ and the generation of Bavel. Why was Noaḥ's generation completely wiped away, while the Tower-builders of Bavel were confused and scattered, but not destroyed? One answer given there is that Noaḥ's generation “were steeped in theft, and therefore they did not survive; but [the Tower-builders], because they loved each other — ‘
and the entire earth was one language’ — therefore they survived.”
In the time of Noaḥ, the earth was full of “חמס” — violence, theft, thuggery — and all living things had corrupted their ways (
Bereishit 6:11-12). The incipient civilization of humanity, the descendents of Ḳayin and Sheit, which had just advanced technologically and culturally through the innovations of Lemekh's children (
4:19-22), was already falling apart. Thuggery and corruption enveloped the earth, and God had to bring the Mabul, the great ‘Withering’, to wash the world clean.
The Deluge was a punishment for humanity, and a lesson for the survivors. Noaḥ's children learned the value of unity, of harmony, of common purpose. Why was the generation of the Mabul scalded and scoured, while the generation of the Tower was simply scattered and separated? “United we stand, divided we fall.” And the settlers in Shin‘ar learned their lesson very well — “let's build a city, and a tower... so that we will not become dispersed across the surface of the entire earth.” (
11:4) No more violence, no more dissolution; like Lemekh's children in the days before חמס, united humanity were ready to invent and create, to bring something new — a מגדל, literally a ‘place of greatness’ — into the world.
The only problem was,
that wasn't God's plan. Humanity must be united; we must respect each other's persons and property; but God had already told Adam and Ḥava (
1:28), and Noaḥ and his children (
9:1), “be fruitful and multiply
and fill the earth” — now that the human race had regained togetherness, it was time to give them a little push. At no point in the story of the Tower of Bavel does God get angry. At no point in the Torah is the dispersion of languages and nations portrayed as a punishment for some unlawful act. It was a preemptive move to preserve God's plan for a world-spanning network of human civilizations in light of humanity's newfound eagerness to work together (
11:6).
In the time of Noaḥ, violence was tearing the human race apart. God sent the Mabul to teach us to ‘play nice’ with each other. Once the Tower proved that we had learned our lesson, it was time to go back to work.
(this idea was developed together with a yeshivamate of mine)