The story of David and Hanun is an example of the proverb (not biblical): “No good deed goes unpunished.”
Though chapter eight highlights David’s decisive victories over a variety of nations, as well as his iron hand in keeping them in line, we see the gracious side of David in chapter nine with Mephibosheth. This graciousness surprisingly extends to Nahash, king of the Ammonites.
We last encountered Nahash in his ruthless treatment of the men of Jabesh-Gilead (2 Samuel 11), but David has been able to strike up a diplomatic and friendly relationship with the king. When Nahash died, David sought to continue good relations with his son.
It doesn’t work. The crown prince Hanun gets poor advice from partisan advisors and commits an act of war. (By the way, the capital city of the Ammonites, Rabbah, is the modern city of Amman, capital of Jordan).
The force of the Ammonites was augmented by mercenary soldiers in far reaching empires. Joab, who leads the forces, knows he is out-gunned and out-manned, but his trust is admirably not in tactics (though he uses them) nor weaponry. In his attempt to protect the people of God, he leaves success solidly in the Lord’s hands – and brings about a decisive victory.
Being a bad guy will eventually result in defeat. Being a good guy will not make you immune to difficulty, but in the end, those who seek to be blessed by God will be triumphant.