This breaking up of whole families, many of whom had perhaps been living happily together for many years, was a drastic but necessary step. Ezra, who seemed to have God-given insight into the divine plan, understood what had to be done and the reasons for it.
The spiritual reasons are, of course, the most important. God says many times in the Pentateuch that intermarriage with pagans is spiritually dangerous (see, for instance, Deuteronomy 7:1-4). It was far more likely that, rather than the heathen spouses being won over to the worship of Israel's God, they would influence their sons and daughters to worship idols. If this were to happen frequently, Israel would soon be entirely idolatrous.
Although there is a bit of physical purity involved in this, God's demands are not for reasons of racial superiority but because He had a purpose for Israel - and the most important purpose is Jesus Christ. To fulfill the prophecies of the promised Seed, He had to be directly descended from Abraham through Judah, Jesse, and David, and because of a curse on Jeconiah (Jeremiah 22:24-30), He could not descend from that wicked king's bloodline. Only these particular circumstances could fulfill the prophecies and establish His righteous claim as the Messiah. Thus, Ezra's action was taken in large part to preserve David's line in preparation for Jesus' birth.
In addition, God wanted Israel to be a holy and separate nation (see Leviticus 19:1-2; Deuteronomy 14:2; 26:19; 28:9). The Israelites were to retain as many of their distinguishing traits and practices as He had given them at the beginning, and they could do this only as long as they remained separate from other nations. In this way, they could be the model nation, a people others would want to emulate, not because of any so-called racial purity or superiority, but because the true God was their God.