[War waged by Israel against their enemy upon orders of their God is one of the issues raised by agnostics/atheists as to why they refuse to believe in the God of the Old Testament. It is likewise used by Christians as an argument for their NT version of God, who is full of grace and mercy unlike this angry, vengeful OT God.
As the Jewish commentators themselves confess in the introduction to this chapter, “We are no longer acquainted with the circumstances that justified the ruthlessness with which it was waged, and therefore we cannot satisfactorily meet the various objections that have been raised in that connection.”
We Sinaites have agreed not to question Israel’s battles fought in defense during their wilderness wandering, nor in offense during the conquest of the Promised Land. We never experienced the perversities and abominations oft-mentioned in these biblical historical narratives. Suffice it to say that we do watch in horror how Hollywood presents the brutality of warring factions in its historical films, whether it be among Vikings, Crusades, Islamic terrorists, Vietnamese, Germans, Japanese, or the American Civil War.
Man’s inhumanity to fellowman perceived as the enemy is forever etched in the memories of the vanquished and the victims. And even in the absence of war, just look at what is happening in civilized societies, in urban centers, horrific crimes perpetrated against people who happen to be in the wrong place at the wrong time.
No, Israel was no more or less different from the nations in defense or offense, though we tend to think it should be, since it supposedly operates on a higher moral standard as dictated by its Divine Commander in Chief.
There is not much commentary offered in Pentateuch and Haftorahs, ed. Dr. J.H. Hertz. Translation is by EF/Everett Fox The Five Books of Moses..– Admin1]
THE WAR AGAINST THE MIDIANITES In XXV,16-18, Moses is bidden to smite the Midianites because they had enticed the Israelites to the licentious and idolatrous worship of Baal-Peor. In the present chapter, he is ordered to carry out the command forthwith; and we are given full details of the campaign.

Image from gci.org
The war against the Midianites presents peculiar difficulties. We are no longer acquainted with the circumstances that justified the ruthlessness with which it was waged, and therefore we cannot satisfactorily meet the various objections that have been raised in that connection. ‘Perhaps the recollection of what took place after the Indian Mutiny, when Great britain was in the same temper, may throw light on this question. The soldiers then, bent on punishing the cruelty and lust of the rebels, partly in patriotism, partly in revenge, set mercy altogether aside’ (Expositor’s Bible). The Midianites affected were only the clans that lived in the neighbourhood of Moab. This accounts for the persistence of Midianites in later periods of Israelite history.
Numbers/Bamidbar 31
1 YHVH spoke to Moshe, saying: 2 Seek-vengeance, the vengeance of the Children of Israel from the Midyanites; afterward you will be gathered to your kinspeople. 3 Moshe spoke to the people, saying: Draft from among you men for the attack-force, let them be against Midyan, to exact the vengeance of YHVH upon Midyan.execute the LORD’s vengeance. The preceding v. refers to Israel’s vengeance on Midian. Both mean the same thing. The cause of Israel is the cause of God. ‘Vengeance’ is here used in the broad sense of retributory punishment.
4 A thousand per tribe, a thousand per tribe for each of the tribes of Israel, you are to send out to the attack-force.5-18. THE EXPEDITION
5 There were mustered, from the divisions of Israel, a thousand per tribe, twelve thousand (men) drafted for the attack-force.delivered. i.e. placed at the disposal of Moses by the leaders of each tribe.
6 Moshe sent them out, a thousand per tribe, to the attack-force, them and Pin’has son of El’azar, priest to the armed-forces, the holy implements and the trumpets for (sounding) trilling-blasts in his hand.Phinehas the son of Eleazar the priest. Phinehas, says Rashi, was especially qualified for this task by the part he played in the Zimri incident (XXV,14,15). His role was that of the priest referred to in Deut. XX,2, whose duty it was to go before the Israelites in battle.
the holy vessels. The Ark and its contents often accompanied the Israelites on their military expeditions; I Sam.IV,3.
in his hand. i.e. at his disposal.
7 They arrayed-their-forces against Midyan, as YHVH had commanded Moshe, and they killed every male,every male. Every adult male.
8 and the kings of Midyan they killed, along with the (other) slain: Evi and Rekem, Tzur, Hur and Reva, the five kings of Midyan; and Bil’am son of Be’or they killed with the sword.Balaam. On his way to his home in Mesopotamia, he must have remained for some time with the Midianites and been their adviser in the matter of Baal-Peor.
with the sword. The Rabbis say that he was slain after a trial by a Beth Din (Sifri).
9 Now the Children of Israel captured the women of Midyan, and their little-ones, and their animals and all their acquired-wealth, and all their goods they took-as-plunder. 10 And all their towns, among their settlements, and all their tent-villages, they burned with fire. 11 They took all the booty and all those-taken, among man and among beast.prey. Booty in livestock; spoil, in goods.
12 They brought to Moshe and to El’azar the priest, and to the community of the Children of Israel the captives and those-taken and the booty, to the camp, to the Plains of Moav, that are by Jordan-jericho. 13 Now Moshe and El’azar the priest and all the leaders of the community, came out to meet them, outside the camp. 14 And Moshe was furious with the commanders of the military, the officers of thousands and the officers of hundreds, who had come back from the armed-force in war; 15 Moshe said to them: You have left-alive all the females! 16 Here, they were (the cause) for the Children of Israel-through the word of Bil’am, of turning away from YHVH, in the matter of Pe’or, so that a plague came against the community of YHVH! 17 So now, kill every male among the little-ones, and every woman who has known a man by lying with a male, kill (as well)! 18 But all the younger-ones among the women who have not known lying with a male- you may keep them alive for yourselves.for yourselves. To employ them as domestic servants.
19-24. PURIFICATION OF THE WARRIORS
19 As for you: pitch-camp outside the camp, for seven days; everyone who killed a person oreveryone who touched a corpse-
decontaminate-yourselves on the third day and on the seventh day,
you and your captives.
without the camp seven days. An enforcement of the law of seven days’ defilement and segregation as laid down in XIX,11.
and your captives. In order to prevent the spread of their contamination by the Israelites’ contact with their garments.
20 And every garment and every vessel of animal-skin and everything made of goats’-hair and every wooden vessel,you are to decontaminate.
as to every garment. Everything that had come in contact with a corpse required purifying.
21 El’azar the priest said to the men of the armed-force who came back from the war:This is the legal Instruction that YHVH had commanded Moshe:
the statute of the law. Contained in XIX, Eleazar now proceeds to enlarge this ‘statute’ of the law in order to meet the present circumstances.
22 However, gold and silver,bronze, iron, tin and lead
23 -anything that can come through fire-
you are to pass through fire, then it will be pure;
however, in Waters Kept-Apart it is to be decontaminated.
And everything that cannot come through fire, you are to pass through water.
everything that may abide the fire. The Talmud understands these laws to mean that every household utensil which, when employed for preparing food, comes into direct contact with fire, must be cleansed with fire. For others, purification by water is sufficient.
water of sprinkling. See XIX,9.
24 You are to scrub your garments on the seventh day, then you will be purified;afterward you may come back into the camp.
25-34. APPORTIONMENT OF SPOIL
25 YHVH said to Moshe, saying:26 Take up the head-count of those taken captive,
among man and among beast,
you and El’azar the priest and the heads of the fathers of the community.
27 You are to halve (equally) the taken-loot
between those wielding (swords skillfully) in war, those going-out to the armed-forces,
and the entire community.
into two parts. Those who fought and those who remained behind were to receive equal shares; and from each of these shares, a tax was levied for the priests and the Levites.
28 And you are to raise a levy for YHVH
from the men of war, those going-out to the armed-forces,
one life out of five hundred,
from humans and from cattle, from donkeys and from sheep.
one soul. i.e. one individual, or, ‘head of cattle.’ One five-hundredth was to be paid by the soldiers for the benefit of the priests; whilst one-fiftieth of the congregation’s share was to go to the support of the Levites.
29 From their half-share you are to takeand give to El’azar the priest a contribution to YHVH.
30 And from the half-share of the Children of Israel you are to take one, withheld from the fifty, from humans and from cattle, from donkeys and from sheep,
from all domestic-animals,
and you are to give them to the Levites,
those charged with the charge of YHVH’S Dwelling.
31 Moshe and El’azar the priest did
as YHVH had commanded Moshe.
32 Now what was taken, over-and-above the plunder that the people from the armed-forces plundered,
were sheep, six hundred thousand and seventy thousand and five thousand, 33 and cattle, two and seventy thousand,
beeves. Old English plural of ‘beef’; used for live animals.
34 and donkeys, one and sixty thousand;35 and human persons,
of women who had not known lying with a male,
all the persons: two and thirty thousand.
36 And the half-share, the portion of those going-out to the armed-forces,
the number of sheep: three hundred thousand and thirty thousand and seven thousand and five hundred.
37 And the levy for YHVH from the sheep was
six hundred and five and seventy,
38 and (from) the cattle, six and thirty thousand,
and their levy for YHVH, two and seventy,

Image from christianimagesource.com
and their levy for YHVH, one and sixty;
40 and (from) human persons, sixteen thousand,
and their levy for YHVH, two and thirty persons.
41 Moshe gave the levy of the contribution of YHVH to El’azar the priest,
as YHVH had commanded Moshe.
42 Now from the half-share of the Children of Israel
that Moshe had halved, from the men who served-as-armed-forces,
43 the half-share for the community, from the sheep-
three hundred thousand and thirty thousand and seven thousand and five hundred;
44 and cattle six and thirty thousand;
45 and donkeys thirty thousand and five hundred;
46 and human persons sixteen thousand.
47 Moshe took from the half-share of the Children of Israel, one withheld out of fifty,
among man and among beast,
and gave them to the Levites, those charged with the duties of the Dwelling of
YHVH,
as YHVH had commanded Moshe.
48 Now there came-near to Moshe the commanders that belonged to the divisions of the armed-forces,
officers of thousands and officers of hundreds,
49 they said to Moshe:
Your servants have taken up the head-count of the men of war that are under our hand,
there has not gone uncounted of us a (single) man!
50 And we have brought-near a near-offering for YHVH
(from) any man who found a vessel of gold, armlets or bracelets,
rings, earrings, or ornaments,
to effect-ransom for our lives, before the presence of YHVH.
offering. Of thanksgiving for their victory and safe return home. Ornaments of gold were worn by roving nomads and traders (Gen. XXXVII,28).
atonement. See Exod. XXX,15.
51 So Moshe and El’azar the priest took the gold from them,all kinds of implements of fine-workmanship.
52 Now all the gold of the contribution, that they set-aside for YHVH:
sixteen thousand and seven hundred and fifty shekels,
from the officers of thousands and from the officers of hundreds.
53 The men of the armed-forces kept-as-plunder, each-man (what) was his.
54 And Moshe and El’azar the priest took the gold
from the officers of thousands and the officers of hundreds,
and brought it to the Tent of Appointment,
(as) a reminder for the Children of Israel, before the presence of YHVH.
into the tent of meeting. And placed it in the treasury of the Tabernacle; Exod. XXX,16; Josh. VI,24.