Numbers 31:54

And Moses and Eleazar the priest took the gold of the captains of thousands and of hundreds, and brought it into the tabernacle of the congregation, for a memorial for the children of Israel before the LORD.

After Israel avenged itself on the Midianites, Moses and Eleazar the priest took the gold of the captains of thousands and of hundreds and brought it into the tabernacle of the congregation for a memorial for the children of Israel before the Lord. The vengeance on Midian meant the destruction of those who had led Israel into sin. Moses reproved the officers for sparing the women and children alive even though no express command to kill them is recorded, because the general order to avenge Israel implied it.

The women were not to be spared because they had been the principal instruments in seducing Israel into the worship of Peor, and sparing them risked the same abomination being enacted again and bringing a new plague or judgment on Israel. As God had put the adulterers of Israel to death by the plague, it was fitting that the adulteresses should be put to death by the sword. The male children were put to death for reasons of prudence and mercy while the female children were spared to become bondwomen and servants, a course justified only in such an age, because the males as they grew up would have endangered the safety of the commonwealth by rebellion to avenge the destruction of their ancestors. The severity blends both justice and compassion and shows that just and true are the ways of the King of saints. The chapter warns that no secret sin can be hidden from God.