In typology, the Midianites signify the filthiness of the lust of the flesh, which is related to the devil Satan and the world (1 John 2:16; 5:19). The Midianites were descendants of Abraham, born of his second wife, Keturah. Hence, by nature they were close to the Israelites in the flesh (Gen. 25:1-2). The Midianites were united with the Moabites, the descendants of Lot born through incest in the lust of the flesh (Num. 22:3-4, 7; Gen. 19:30-38). Furthermore, the Midianites were one with the Ishmaelites, the descendants of Abraham by the flesh, who sold Joseph into Egypt (Gen. 37:27-28, 36). The Midianites were also connected with the Amalekites, the descendants of Esau (Judg. 6:3, 33; Gen. 36:12). Finally, the Midianites produced Balaam, who ensnared the children of Israel in fornication and idolatry (Num. 22:7; 31:16).
By ensnaring the sons of Israel in fornication and idolatry, the Midianites offended Israel to the uttermost, with the result that more than twenty thousand lives were lost. God would not forget that, and He charged Moses to avenge Israel on the Midianites.