Numbers 31 tells of a war between the Israelites and the Midianites. Midian was a son of Abraham by his second wife, Keturah. That would make him a half-brother to Isaac and Ishamael, and an uncle, I guess, to Jacob. The point is that the Midianites and the Israelites are fairly close relatives.
We are told that this is a war of revenge, ordered by YHWH, apparently for the events of chapter 25 where Midianite women seduced Israelite men into the worship of other gods.
Phinehas, next in line to be high priest, is chosen to lead the troops against the Midianites. He has already shown just how he feels about Midianites (Numbers 25:6 ff.).
When the violence ends and the smoke clears, the Israelites have won a decisive victory and suffer no casualties. Their spoils: wealth and women. The men can keep the wealth. The women are another matter. These are, after all, the same women who were seducing the men to worship idols. Moses orders the women killed. Except for the virgins. They can keep the virgins.
War is ugly. Although parts of the Scriptures condone war and all of its ugliness I keep in mind that Jesus, who is the final authority for Christians, said "Love your enemies and pray for those who persecute you."
I have a friend whose pickup truck sports a bumper sticker:
WHEN JESUS SAID "LOVE YOUR ENEMIES"
I'M PRETTY SURE HE MEANT DON'T KILL THEM.
We could probably add, "Don't kill their women or treat their virgin daughters as spoils of war."
The prophet Balaam, he of the talking donkey, is a casualty of this war. Balaam was a prophet of YHWH. Balaam was not a Midianite. Here he is said to have advised the Midianite women to seduce the Israelite men. The record concerning Balaam is mixed at best. It would appear, once more, that multiple traditions have been combined into a single, not always coherent, account.
The soldiers and their captured spoils are subjected to purification rites to cleanse themselves of the ritual impurity contracted in warfare.
In chapter 32 we read that the tribes of Gad, and Reuben, along with the half-tribe of Manassah, settle in the Trans-Jordan. The land here is good for cattle, they say. Moses balks at the request. Unwillingness to cross the Jordan is what led to the last 40 years of nomadism in the wilderness. When the Gadites, Reubenites, and Manassites offer to help the other Israelites conquer and settle Canaan, Moses gives his permission.
Towns are rebuilt. Others are conquered. The wives and children of the 2-1/2 tribes are settled. And we are ready to enter Canaan. But first....
Next: Numbers 33-34