"Avenge the vengeance of the children of Israel against the Midianites; afterward you shall be gathered unto your people" (Numbers 31:2). Rabbi Judah said: Had Moses wished to live for some more years, he would have lived, for the Holy One, blessed be He, had made his death depend upon coming after the vengeance against Midian. Moses said: Shall I, in order that I may go on living, hold back the vengeance of Israel upon the Midianites? Immediately, "And Moses spoke unto the people, saying: Arm men from among you" (Numbers 31:3).
Moses Hastens His Own Death to Avenge Israel on Midian
Midrash Tanchuma Buber, Matot 3:1
נקום נקמת בני ישראל מאת המדינים אחר תאסף אל עמך (שם לא ב). אמר ר' יהודה אילו רצה משה לחיות כמה שנים היה חי, שתלה הקב"ה מיתתו אחר נקמת מדין, אמר משה בשביל שאחיה אעכב נקמת ישראל מן המדינים, מיד וידבר משה אל העם לאמרה חלצו מאתכם אנשים (שם שם ג).