In 1 Sam 21, we read that God was displeased because Saul had not honored a covenant agreement with the Gibeonites, even though the oath was gained dishonestly; thus whatever the reason for the covenant having been made – it should be honored. Why then, was it permitted in the book of Ezra to ‘put away’ the non-Jewish wives whom they had taken in disobedience.
When Joshua entered into a covenant with the Gibeonites, he did so without seeking the Lord and was deceived. When he learned of the deception, he essentially consigned the Gibeonites to positions of servitude among the Israelites from then on, a penalty to which they agreed.(Joshua 9:23) But Saul was trying to exterminate them, which was a violation of the law that protected servants from such treatment.
In the case of the foreign wives, in Deut. 7:3 it was forbidden for Israelites, and especially for Priests and Levites, to marry foreign women. With the exception of those women who had been legally taken as captives, the Israelites were to keep themselves separate. (Deut. 21:10-14) The reason for this is that God knew that the foreign wives would entice their husbands into idolatry. Marriage to a foreigner was therefore considered to be an illegal union.
The Israelites had just barely returned from 70 years of servitude for disobedience, and Ezra was terrified to think that the Lord might put them back into captivity for this violation of the Law. Other leaders agreed, and so they devised a plan to voluntarily send their foreign wives away and come back into compliance with the Law in an effort to show God that they had learned their lesson. Their voluntary repentance was accepted and judgment was averted.
So even though the Gibeonites were protected and the foreign wives were banished, both actions were consistent with God’s law.