David has a good reputation with the nations around him because while he was fleeing from Saul he worked alongside these nations to destroy and conquer the neighboring nations. The people of the region knew David, they trusted him, and over time they had built a relationship with him. But that only lasts a generation. The king of the Ammonites had died and this king had a good relationship with David. But his son was given bad advice and told not to trust David and to deal shamefully with the messengers of David who came to give consolation to the son, now the king, who had lost his father, who was the king. Are you following?
As a result the Ammonites became "odious" do David. Literally that means that they were hated by David because they treated his people wrongly. There were battles and alliances formed until the end of the day the Israelites won, as you would expect, and the people in the region had to once again make terms with David. They could have saved a lot of heartache if they had just trusted that David would have dealt fairly with them. As a result of all this mess the other nations stopped trusting the Ammonites because they were the ones who dragged them into this mess in the first place.