Vengeance on the Midianites—and on Balaam
As the last task to perform before Moses’ death, God commands him to take vengeance on the Midianites because they, with the Moabites, deliberately set out to destroy the Israelites through their idolatrous religious practices. Furthermore, making a stark example of the Midianites in destroying them would serve as a deterrent to future apostasy. Incredibly, not a single Israelite dies in the war, moving their leaders to make a special offering. The officers over thousands, etc., come to Moses to make a voluntary offering to God to cover everything, an atonement offering (verses 48-50). God is with Israel in this righteous battle—signified by the fact that Phinehas also goes to war with the Ark of the Covenant and the two silver trumpets. It is God who gives them the victory.
Interestingly, verse 8 mentions that one of the men who was slain in the war was Zur. This Zur was apparently one of the instigators of the plot to bring false worship to Israel. Indeed, it was his daughter, Cozbi, that Zimri had brazenly paraded before the congregation of Israel before they were both slain by Phinehas (Numbers 25:14-15 Numbers 25:14-15  Now the name of the Israelite that was slain, even that was slain with the Midianitish woman, was Zimri, the son of Salu, a prince of a chief house among the Simeonites.
 And the name of the Midianitish woman that was slain was Cozbi, the daughter of Zur; he was head over a people, and of a chief house in Midian.
American King James Version×). In verse 9, we see the women of Midian taken captive in the wake of the battle. Moses, however, is incensed at this, as these are the same women who led Israel astray with the Moabites—and he commands that all but the virgins among them be put to death (verses 14-18). Besides their idolatrous practices, it is also possible that the promiscuous Midianites had sexually transmissible diseases that God wanted to keep out of Israel as well.
Verse 16 is the verse that actually explains what happened in the incident of Baal Peor. We learn that it was the “counsel of Balaam” that the Midianite women followed when they caused the children of Israel to sin against God, resulting in the plague that cost 24,000 lives. Without this explanation, readers of chapters 22-24 might give Balaam the benefit of the doubt, assuming him to have been a prophet who was following God’s will. But note this: Balaam did not “die the death of the righteous,” as he had so eloquently prayed (Numbers 23:10 Numbers 23:10Who can count the dust of Jacob, and the number of the fourth part of Israel? Let me die the death of the righteous, and let my last end be like his!
American King James Version×). Rather, he died by the edge of the sword—being justly put to death along with the Midianites by the Israelites at God’s command (verse 8).
So just what lesson can we learn from Balaam? Notice this from the article on him in The Complete Who’s Who in the Bible: “2 Peter 2:15 2 Peter 2:15Which have forsaken the right way, and are gone astray, following the way of Balaam the son of Bosor, who loved the wages of unrighteousness;
American King James Version×, Jude 1:11 Jude 1:11Woe to them! for they have gone in the way of Cain, and ran greedily after the error of Balaam for reward, and perished in the gainsaying of Core.
American King James Version×and Revelation 2:14 Revelation 2:14But I have a few things against you, because you have there them that hold the doctrine of Balaam, who taught Balac to cast a stumbling block before the children of Israel, to eat things sacrificed to idols, and to commit fornication.
American King James Version×warn the NT people of God against allowing a smooth-talking pagan to capitalize on his knowledge in the form of religiosity and twist it to his own deadly end. A veneer of piety disguises the shallow convictions which can be bought for a price (Numbers 22:17 Numbers 22:17For I will promote you to very great honor, and I will do whatever you say to me: come therefore, I pray you, curse me this people.
American King James Version×) and superficial repentance (v. 34) which is short-lived. 2 Peter 2:15-16 2 Peter 2:15-16  Which have forsaken the right way, and are gone astray, following the way of Balaam the son of Bosor, who loved the wages of unrighteousness;  But was rebuked for his iniquity: the dumb ass speaking with man’s voice forbade the madness of the prophet.
American King James Version×views Balaam as a man of prophetic talent but with a desire to use the gifts of God to further his own ends. So, Peter warned of the danger of ‘empty’ words because they act as a cover for evil desires. The Christian must appreciate that such emptiness of heart will be exposed on judgment day (Jude 1:11 Jude 1:11Woe to them! for they have gone in the way of Cain, and ran greedily after the error of Balaam for reward, and perished in the gainsaying of Core.
American King James Version×). For the apostle John writing to the compromising church in Pergamum the worse sin is not actually that of self-deception, because that in the end will be exposed. Rather, Balaam’s leading of Balak [and thus Israel] into further spiritual adultery is far worse. And so, the worst of judgments is saved for those who knowingly deceive others. Like Balaam their sin eventually catches up with them (see Numbers 31:8 Numbers 31:8And they slew the kings of Midian, beside the rest of them that were slain; namely, Evi, and Rekem, and Zur, and Hur, and Reba, five kings of Midian: Balaam also the son of Beor they slew with the sword.
American King James Version×, Joshua 13:22 Joshua 13:22Balaam also the son of Beor, the soothsayer, did the children of Israel slay with the sword among them that were slain by them.
American King James Version×)” (Paul D. Gardner, ed., 1995).