In Numbers 31 the whole chapter is about vengeance on Midian. The ESV Study Bible shares: The Midianites were a group of nomadic tribes who inhabited the deserts on the fringes of Canaan. They were associated with the Ishmaelites, Amalekites, and Moabites. It is the Moabite Midianites who are the target here. Instigated by Balaam (v. 16), they had seduced the Israelites into worshiping Baal at Peor (ch. 25), so a brief but fierce military campaign is launched against them, for persuading Israelites to worship other gods is a capital offense, according to Deuteronomy 13. As the last campaign headed by Moses (Num. 31:1–2), this one sets precedents for the coming invasion of Canaan.