Num 31:14 And Moses was angry with the officers of the army, the commanders of thousands and the commanders of hundreds, who had come from service in the war.
Num 31:15 Moses said to them, “Have you let all the women live?
Num 31:16 Behold, these, on Balaam’s advice, caused the people of Israel to act treacherously against the LORD in the incident of Peor, and so the plague came among the congregation of the LORD.
Num 31:17 Now therefore, kill every male among the little ones, and kill every woman who has known man by lying with him.
Num 31:18 But all the young girls who have not known man by lying with him keep alive for yourselves.
The sword of war should spare women and children; but the sword of justice should know no distinction, but that of guilty or not guilty. This war was the execution of a righteous sentence upon a guilty nation, in which the women were the worst criminals. The female children were spared, who, being brought up among the Israelites, would not tempt them to idolatry. The whole history shows the hatefulness of sin, and the guilt of tempting others; it teaches us to avoid all occasions of evil, and to give no quarter to inward lusts. The women and children were not kept for sinful purposes, but for slaves, a custom every where practised in former times, as to captives. In the course of providence, when famine and plagues visit a nation for sin, children suffer in the common calamity. (Henry)
Treatment of the Prisoners. – When Moses went out to the front of the camp with Eleazar and the princes of the congregation to meet the returning warriors, he was angry with the commanders, because they had left all the women alive, since it was they who had been the cause, at Balaam’s instigation, of the falling away of the Israelites from Jehovah to worship Peor; and he commanded all the male children to be slain, and every woman who had lain with a man, and only the young girls who had hitherto had no connection with a man to be left alive. (Brown)
Moses was angry because the children of Israel failed to see the great danger of sexual immorality and idolatry posed by these women who before had led the men of Israel into these exact sins. God’s people may be deceived by things that were a threat, but do not seem to be a present danger. The Israelite officers of the army thought these women were safe, but they were more dangerous to Israel than an army of mighty warriors. Israel could overcome mighty warriors if they were spiritually strong; but if they were seduced into immorality and idolatry, they would certainly fall. We often think of many things as dangerous to us as the people of God – hostile government, secular humanism, academic attack, and so forth. But when God’s people accept things among them that open the door to immorality and idolatry, this can be a much greater danger than any of those other things.
God has the right to judge not only individuals but also communities of all different sizes. Such judgments go beyond punishing individuals for their personal guilt; judgment comes upon the society as a whole, including those who may not be personally and individually guilty (such as children; the little ones). Sometimes God sends these judgments directly (as in the Genesis flood or with Sodom and Gomorrah), and sometimes God sends nations as instruments of His judgment (as with the Assyrians against the northern kingdom of Israel and the Babylonians against the southern kingdom of Judah). In the broader conquest of Canaan, God uniquely used His people (Israel) as that instrument of judgment.
This harsh judgment often makes us uncomfortable but is rooted in both God’s fundamental right to judge (Psalm 9:8, 50:6), and in His merciful granting of much time for people to repent (Genesis 15:16). We can trust that God is a righteous judge (Genesis 18:25, Psalm 7:11). (Guzik)
“For this action I account simply on the principle that God, who is the author and supporter of life, has a right to dispose of it when and how he thinks proper; and the Judge of all the earth can do nothing but what is right.” (Clarke)
“The nations today are at risk from the judgment of God. This is true whether they acknowledge it or not. One day that judgment will come. At that time there will be no weeping over women and boys who died in ancient Midian three and a half millennia ago; at that time the judgment of God will transcend anything ever written in the harshest Scripture.” (Allen)