If you trace the Messianic timeline from the beginning of time until the present, you will find it in the most unlikely of places, if you read the midrash and commentaries.. Just think of the descendants of Lot and his daughters, Yehuda and Tamar, David and Batsheva and Ruth and Boaz. Moab,it seems, had in it the ultimate spark of Mashiach (Messiah).
Why did Mashiach have to emerge from such questionable and improbable relationships? Rabbi Duvi BenSoussan explains that Satan will be eradicated once Mashiach arrives. Therefore G-d has to hide the process in the most unlikely of places so that Satan can’t eliminate the realization of a redeemer.
Rabbi Duvi BenSoussan further explains that Zimri was lined up with this thought process. He knew Mashiach was going to emanate through Moab. Once he saw Cozbi was a princess of Moab and embodied malchut, royalty, (she was a princess) he believed this was the union that would bring Mashiach.
The Gemara (Sanhedrin 82b) brings one opinion that says Zimri cohabited with Cozbi 424 times. The kabbalist, Imrei Yosef, notes that the gematria of 424 equals the words “Mashiach ben David.” Zimri believed he was delivering Mashiach. This is exactly why the Sanhedrin (see Yerushalmi Sanhedrin 9:7) wanted to put Pinchas in cherem, for they believed Pinchas had just killed the potential Mashiach.
Rabbi Akiva, who was a gilgul of Zimri, had that same passion to bring Mashiach as Zimri did. He thought he had it Bar Kochba, but it didn’t materialize. However, Rabbi Akiva does the tikkun for Zimri as Rabbi Akiva died through sanctifying G-d's Name, kiddush Hashem which rectified the desecration, chillul Hashem done by Zimri.
What does all of this mean for us?
Firstly, you see the great leaders in our history desired Mashiach with great fervor so that all the troubles, whether as Zimri hoped in Israel or as Rabbi Akiva hoped in galut, would come to an end. This must make an impression on us to have our minds on Mashiach constantly, especially in today’s times when the challenges in Israel and the diaspora are unprecedented.
Secondly, the story of Zimri exhibits the fact that the four amos of halakha supersedes unlawful, zealous acts. We must first have our full allegiance to the halakha and then take action. In this way we can greet Mashiach in the right way and at the right time