וַיְדַבֵּר ה’ אֶל מֹשֶׁה לֵּאמֹר נְקֹם נִקְמַת בְּנֵי יִשְׂרָאֵל מֵאֵת הַמִּדְיָנִים אַחַר תֵּאָסֵף אֶל עַמֶּיךָ וַיְדַבֵּר מֹשֶׁה אֶל הָעָם לֵאמֹר הֵחָלְצוּ מֵאִתְּכֶם אֲנָשִׁים לַצָּבָא וְיִהְיוּ עַל מִדְיָן לָתֵת נִקְמַת ה’ בְּמִדְיָן (Matos 31:1, 31:2, 31:3)
God spoke to Moshe saying,”Take revenge for the children of Israel against the Midianites; afterwards you will be gathered to your people.” So Moshe spoke to the people, saying, “Arm from among you men for the army, that they can be against Midian, and carry out the revenge of God against Midian.”
Rashi says, וידבר משה וגו’: אף על פי ששמע שמיתתו תלויה בדבר עשה בשמחה ולא איחר: Moshe spoke: Although he heard that his death depended on the matter, he did it joyfully, without delay.
The Chanukas Hatorah explores this Rashi further. He explains that Hashem told Moshe to avenge the Jews against the Midianites, after which he would pass on. When Moshe spoke to the people, he told them to avenge God against Midian. The Midianites needed to be punished for desecrating the Jews and heaven by causing the Jews to sin. However, Moshe changed the wording of Hashem’s statement because if he were to tell them to avenge themselves, they would forgive Midian in an effort to keep Moshe alive. Moshe purposely told them to avenge Hashem; we can’t forgive on His behalf, so they would have to attack Midian and through that, cause Moshe to die as he was supposed to.