Deuteronomy 23:4
Because they met you not with bread and with water in the way, when ye came forth out of Egypt; and because they hired against thee Balaam the son of Beor of Pethor of Mesopotamia, to curse thee. Because they met you not with bread and with water in the way, when ye came forth out of Egypt; and because they hired against thee Balaam the son of Beor of Pethor of Mesopotamia, to curse thee.
The law set Ammonites and Moabites apart by barring them from the congregation of Israel. That bar was laid down because of how they had acted toward Israel on the way out of Egypt. Their course was one of cruelty and treachery, in refusing needed help and in seeking harm against Israel. For that reason the exclusion was not temporary but permanent.