This is an adaptation of some of Rabbi Yitzchak Twersky's ideas in his Amitah Shel Torah.
While it says in Devarim 34:10 that Israel never had a prophet like Moshe, the medrash infers from the wording, there was such a prophet for the nations of the world, ie: Bilam. The question of the talking donkey can not be ignored. One can suggest that the donkey was mirroring Bilam back to himself. Clearly, the aton/donkey only spoke because God made it speak. Through this Bilam was taught (although he didn't eally learn the lesson) that the same control of G-d applied to him as to the donkey (as opposed to his previous contention that he had the power to curse and bless).
Chukat and Balak have parallel themes and this is the deeper meaning of that statement of Chazal. In each parsha the Jews and then the nations, respectively, are taught the lesson that God and not man controls everything .
Medrash Tanchuma on Vayeitzei 1:3 says that Bilaam and Lavan are "the same person." Bilaam was from Aram (see Rashi, Bamidbar 22:5, where it says Balak sent word to Petora which Onkulus translates as Petor-Aram). Lavan is referred to as an Arami because h tried to destroy Israel, as Lavan had also attempted. Another personality parallel is that of Balak and Paroh. In Bamidbar 22:3 Balak's fear of the Jewish People's growth is expressed with the words "Vaykatz Moav mipeni Bnei Yisrael." In Shemot 1:12 it says about Mitzraiyim, "Vayakutzu mpeni Bne Yisrael."
Paroh and Lavan have different means but same ends in mind. Lavan attempted to uproot Judaism by pulling Yaakov’s family into the realm of Avodah Zarah. Paroh planned to simply destroy the Jewish people through warfare (see Ramban end of Shemot).
Based on Bamidbar 22:2 (with Rashi ) its clear that Balak’s call to Bilaam was predicated upon what Bnei Yisrael had done to the Emori. In Chukat the Jews are blocked from going the route they planned to go. In Shemot 15:15 it states that the chieftians of Edom were/would be confounded, that trembling did/would grip the powers of Moav, and that the Jews would pass through their lands (ad yavor). Edom undid what these words in Az Yashir predicted (Shmot 15:16 ad yavor amcha Hashem) by stating Lo Taavor Bi (Bamidbar 20:18). The shirah at the end of Chukat serves as a second Az Yashir and reinstated the fear of Bne Yisrael in the world. Moav is described in Az Yashir as being afraid and when the time comes, this prediction plays out.
In Yehoshua 2:9 the nations of the world are described as trembling (namogu kol yoshvei haaretz tachteihem). The passuk cited above (Shemot 16:16) concludes with the words "Namogu kol yoshvei Cananaan." The words in Yehohua clearly echo the words of Az Yashir. Rachav explains that the fear of Bne Yisrael is based on what God did at Yam Suf and what He did to Sichon and Og. We can explain that in giving these two examples Rachav is saying that the later events reinstated the power of the original message. Now that the Jews are back on track an attempt to undo the process of redemption is immediately put into play. Just like Lavan and then Pharoah sensed the impending ascent of the Jewish people, now Balak and Bilaam take their turn.
It is important to notice the difference between the two dialogues that Bilaam has with Balak’s messengers. In the first the word used to mean to curse is Arah, (22:6). the second time the word used to mean curse is Kavah (22:11). Arah means to really change the situation. Kavah means to curse in the more colloquial sense, to vent anger or frustration. The second difference flows from the first: The first statement was more confident. When Bilaam tells God about the first meeting he leaves out the fact that Balak said "I know that who you bless will blessed those who you curse will be cursed." Bilaam was trying to trick God.
It's worth noting that Bilaam said "if you give me your house full of silver and gold I can't go against God’s word." (22:18) Based on 31:16 it seems (although Ramban disagrees) that Bilam was the mastermind of the Baal Peor incident. In 25:8 the crisis is ended when Pinchas stabs the major offender. The pasuk specifically says that Pinchas came into the tent, the Kubah, and stabbed the woman in her stomach, kabatah. It seems like the passuk is going out of its way to use and reuse a form of the same word. This indicates a connection to Bilam’s curse which in the end is described with the word Kabah. Bilaam finally gets at Bnei Yisrael through the advice he gives about Baal Peor. He attempts to fulfill his mandate of "Lech kavah li" through events that reach their peak inside a "kubah" and in the end Pinchas undoes the damage by piercing through "kabatah.
Bilaam’s test was to accept that whatever God says goes. As much as God made His will clear Bilaam obscured it in his mind he ran from what he knew was the clear truth. Pinchas does the opposite. He was in a situation in which the truth was clouded, God’s will was not being done, no one (including Moshe, see Rashi on that passuk 25:6 who says that someone taunted Moshesaying " if you say a Midianite women is forbidden, who allowed you, you married a Bat Yitro!?" (Tzipprah, a Midianite). Pinchas recalls the “halacha” and steps forward and pierces through to the truth.
The similarity in words reflects a poetic justice. The words reflect that the truth that Bilaam tries to run from by cursing, kavah, that was turned inside out and exposed and revealed when Pinchas entered the tent, kubah and stabbed the idolatress temptress in her stomach, kaba.
May we be blessed to be protected from destruction, to be internally strong, and to forever grow through the wellsprings of our Torah.