Numbers 31:3
And Moses spake unto the people, saying, Arm some of yourselves unto the war, and let them go against the Midianites, and avenge the LORD of Midian. And Moses spake unto the people, saying, Arm some of yourselves unto the war, and let them go against the Midianites, and avenge the LORD of Midian.
Moses told the people to arm some of themselves for war to go against the Midianites and execute the Lord's vengeance upon Midian, in obedience to the Lord's command to take vengeance on them. The order came after the Midianites enticed Israel into sin at Peor, which brought a plague upon the congregation, and after they sought Israel's destruction.
The war was God's judgment upon the Midianites for leading Israel into sin, and at the same time an act of mercy and protection toward Israel against a corrupting and hostile people. Israel was to act in it as God's instruments, not to satisfy malice or personal revenge but from zeal for God's glory, so the command reveals both justice toward the guilty and mercy toward Israel.
The Midianites were punished swiftly because they were especially dangerous enemies, unlike the Amalekites, who fell upon Israel's weak and weary but whose punishment came much later. The command was carried out by a force of one thousand men from each tribe, sent out under Phinehas.