The historical hostility of the Ammonites and Moabites toward the Israelites after their departure from Egypt serves as the foundation for their exclusion from the assembly of God. Rather than showing a desire for peace, these nations actively sought to cause harm. During the Israelites' journey through the desert, the Ammonites and Moabites failed to greet them with basic provisions of bread and water [ביאור שטיינזלץ, מצודת דוד].
The connection between withholding food and the subsequent hiring of Balaam exposes the deep-seated malice behind their actions. Had these nations been motivated by a genuine fear of the approaching Israelites, the natural response would have been to offer food and water in an attempt to secure a peace treaty. Their refusal to provide basic sustenance proves that their actions were driven by pure hatred rather than self-preservation, which ultimately led them to hire Balaam to curse the Israelites [מלבי״ם].
Ultimately, God transformed the intended curse into a blessing. This divine intervention underscores the severe reality of the threat; without God actively stepping in to reverse the curse, Balaam's words would have inflicted actual, tangible harm upon the nation [מלבי״ם]. Furthermore, concluding the historical account with this transformation serves a specific purpose for the reader. There was a deliberate choice to avoid ending the narrative on a negative note, choosing instead to finish with a powerful reminder of divine rescue and blessing [מצודת דוד].