Numbers 31:18

But all the women children, that have not known a man by lying with him, keep alive for yourselves.

Numbers 31:18 belongs to the account of Israel's war of judgment against Midian. That war was commanded by God as divine judgment, not undertaken from personal malice or revenge, with Israel acting as His instruments from zeal for His glory. The command came as Moses' response after Israel had spared the Midianite women and children.

The direction to keep alive means to preserve only the female children who had not had sexual relations. The other captive women were put to death at Moses' command as the most guilty and dangerous enemies of Israel. They had led Israel into sin at Peor, and keeping the idolatrous, licentious women as captives would endanger Israel's morals. Sympathy that excuses or shields those guilty women is contrary to God's will.