Numbers 31:14
And Moses was wroth with the officers of the host, with the captains over thousands, and captains over hundreds, which came from the battle. And Moses was wroth with the officers of the host, with the captains over thousands, and captains over hundreds, which came from the battle.
This episode belongs to Israel's divinely commanded war against Midian as judgment for seducing Israel into sin by enticing them to idolatry. Moses was wroth with the officers of the host, the captains over thousands and captains over hundreds which came from the battle, because they had brought back and spared the Midianite women alive. Those women had helped lead Israel into sin through Balaam's counsel, bringing a plague upon the congregation. That seduction into sin took place at Peor. The captured Midianite women were put to death because they were regarded as the most guilty and dangerous enemies of Israel.
Moses' anger after the battle was grief and indignation over the deceitful schemes that had led Israel into sin. His response reflected concern for God's justice and mercy, not a desire for personal revenge. In this judgment Israel was to act as God's instrument, seeking His glory.