Hashem informed Moshe Rabbeinu that he would leave this world once Klal Yisrael destroyed Midyan. Then Klal Yisrael would be avenged. Once Klal Yisrael exacted vengeance, Moshe’s “work” (so to speak) would be complete. Although Moshe was acutely aware that once he completed this mitzvah he would die, he executed the vengeance with amazing alacrity. A mitzvah is a mitzvah, even if it meant that it would hasten his own demise.
The Torah writes that the Jewish People waged war with Midyan, and they succeeded in killing all males. Among them was Bilaam ben Be’or, the pagan prophet who was hired by Balak, king of Moav, to curse the Jews. Since vengeance against Midyan was the criterion for Moshe’s passing from this world, and Bilaam was part of that vengeance, it makes sense that Moshe’s death was dependent upon Bilaam’s death. It was almost as if Moshe could not die as long as Bilaam remained alive. Why is this?
Horav Yaakov Yitzchak HaLevi Ruderman, zl, explains this based on Chazal’s commentary to the pasuk in Devarim 34:10, V’lo kam Navi od b’Yisrael k’Moshe; “Never again has there arisen in Yisrael a prophet like Moshe.” Chazal (Sifri) note the Torah’s emphasis on Yisrael, which they say implies that another prophet would never arise in Yisrael that would achieve Moshe’s stature. In the gentile nations, however, such a prophet could possibly exist (albeit, on a contrasting, spiritual level of defilement). This was Bilaam who, after strenuous preparation under certain circumstances and criteria, could communicate with G-d. In other words, on some plane, Bilaam was the pagan analogue to Moshe. Taking this further, the Rosh Yeshivah quotes Koheles 7:14, Gam es zeh l’umas zeh asah Elokim; “G-d has made the one as well as the other.” Chazal (Chagigah 15a) say, “Everything that Hashem created, He created a counterpart (l’umas zeh). He created the righteous; He created the wicked; He created Gan Eden; He created Gehinnom.” We infer from Chazal that the world has to function in a balanced way: for every good creation, a like creation must exist in opposition. Thus, the Rosh Yeshivah explains, the relationship between Moshe and Bilaam was zeh l’umas zeh. Bilaam was Moshe’s counterpart, the balance of evil to good. What Moshe achieved in purity and sanctity, Bilaam counter-achieved in spiritual defilement and impurity.
As such, we understand why it was necessary for Moshe’s life to end once Bilaam was no longer alive to balance his kedushah. As long as Bilaam lived, Moshe lived. Once Bilaam died, Moshe could return to his Source. With this in mind, we might understand why Moshe rushed to execute the mitzvah of vengeance. He understood that as long as Bilaam lived, a high level of defilement would pervade the world. He was willing to give up his life in order to rid this world of Bilaam’s spiritual contaminant.