This was because the people of Ammon and Moab did not give food and water to the Israelites on their way out of Egypt. Instead, they paid money to Balaam to curse Israel, but our God turned the curse into a blessing. 1
References for Nehemiah 13:2
13.2 Nu 22.1-6.