Numbers 31:2

Avenge the children of Israel of the Midianites: afterward shalt thou be gathered unto thy people.

The command gave Moses his last work before death, to avenge Israel upon the Midianites, and the one who commanded him was God Himself, Christ as Israel's invisible leader. That avenging meant making war with Midian, an act of God's wrath and judgment executed through Israel. The cause of the vengeance was that Midian had vexed Israel with wiles, leading and enticing and seducing the people into sin and transgression of God's law and idolatry. In doing so Midian also sought Israel's destruction.

Midian was judged quickly because it was a more dangerous enemy than the Amalekites who had earlier attacked Israel. God had shown Midian mercy and evidence of His power, and He bears long with such wicked nations. But once they filled up the measure of their iniquity He brings swift destruction upon them.

The campaign was divine judgment, not personal malice or revenge. Moses was to carry it out as God's instrument, from zeal for God's glory. It displayed both justice toward the guilty and mercy in protecting Israel. Such a command to punish was not cruelty contrary to benevolence, but the just right of Him who made the world and men, who has unlimited control over the work of His hands, against whom there is no injustice, and who as Ruler of the world punishes rebellion, contempt of His people, and worship of idols.

Israel promptly carried out the command by sending a thousand men from each tribe under Phinehas. After carrying out this mission Moses would be gathered to his people, meaning his death would follow its fulfillment.