Deuteronomy 23:5

Nevertheless the LORD thy God would not hearken unto Balaam; but the LORD thy God turned the curse into a blessing unto thee, because the LORD thy God loved thee.

The statute to which this declaration belongs barred the Ammonites and Moabites from entering the congregation of Israel. That exclusion was a judgment upon their cruelty toward Israel. It was likewise a judgment upon their treachery toward Israel.