And the LORD said to me, Distress not the Moabites, neither contend with them in battle: for I will not give you of their land for a possession; because I have given Ar to the children of Lot for a possession.Deuteronomy 2:9
A great deal of Israelite distress had to do with their interactions with the Moabites. Indeed it was an interaction with the Moabites on the very borders of Canaan that led to an extermination of a large number of Israelites due to the prostitution explosion (Numbers 25). David was obviously aware of this Deuteronomy instruction and his family’s debt to Moab (the story of Ruth and Naomi) when he did the following.
… smote Moab, and measured them with a line, casting them down to the ground; even with two lines measured he to put to death, and with one full line to keep alive. And so the Moabites became David’s servants, and brought gifts.2 Samuel 8:2
This is not the only time David spared the life of a known enemy
Next time you think you have a victory or think you are doing a great and wonderful thing consider how many people might be paying for it.