HaShem's anger at Bilam stemmed from Bilam's active attempts to harm Israel, his advising the Midianites to entice the nation to sin.
SOURCES: R"A Friedman, as relayed by R"Y Medan
Chronology – This approach assumes that the interactions between Bilam and Balak in Bemidbar 22 take place at the same time as the story of the Sin of Baal Peor in Bemidbar 25, and that the stories must be interwoven to appreciate the full picture.
"ד בַר בִל עָם לִמ סׇר מַעַל בַי״י עַל ד בַר פ עוֹרהֵן הֵנָה הָיוּ לִב נֵי יִש רָאֵל בִ " – This approach, following Bavli Sanhedrin, understands this verse to mean that it was Bilam's idea to induce the Israelites to sin with the Midianites at Baal Peor. However, it uniquely suggests that this advice was given, not after Bilam's attempt to curse the nation failed, but at the very outset of the story. Already when HaShem initially forbade Bilam from going to curse the nation because "they are blessed" (22:12), Bilam suggested to Balak that he instead cause the nation to stumble and sin so that they would no longer be deserving of blessing.
"לֹא תָאֹר אֶת הָעָם כִי בָרוּךְ הוּא" – Though the text does not share that Bilam relayed this part of HaShem's words to the officers, this position assumes that he did. It is this knowledge that leads to the alternative plan of inciting to sin.
Did HaShem change His mind? According to this reading, HaShem did change His mind between the first and second visits of Balak's messengers, but only due to a change in circumstances. During the first visit, Israel was free of sin and worthy of HaShem's protection, and so Bilam was prevented from cursing the nation. By the second visit, however, the nation had sinned at Baal Peor (in the wake of Bilam's advice) and were deserving of punishment. As such, HaShem acquiesced that Bilam be the tool to inflict it. HaShem, however, added a caveat: "וְאַךְ אֶת הַדָּבָּר אֲשֶר אֲדַבֵר אֵלֶיךָ אֹתוֹ תַעֲשֶה ", leaving room for the nation to repent and HaShem to change His mind again.
HaShem's wrath at Bilam – As this position uniquely suggests that Bilam not only had permission to go with the Moabites, but also to curse the nation, HaShem's ensuing wrath appears all the more misplaced. This position suggests that HaShem's about-face is once again the result of changed circumstances. By morning, when Bilam departed, Pinchas had killed the guilty parties at Baal Peor, appeasing HaShem's anger. As such, the nation was once again deserving of Divine protection. Moreover, HaShem's wrath at the nation was transferred to Bilam, who was guilty of causing them to sin to begin with.
Why doesn't HaShem have Bilam return home? It is possible that after HaShem's anger at the Children of Israel was appeased and His love restored, He desired not only that the nation not be cursed, but that they be blessed instead. Thus, the angel tells Bilam to continue on his journey but to say only that which HaShem tells him, a blessing.
The encounter with the angel – This approach might suggest that the angel was sent to punish Bilam for his deed. However, we would have expected that at some point during the encounter, he would explain as much to Bilam. It is possible that the angel did in fact explain this, but this is omitted from the text, as it would not have been understandable given that the story of Baal Peor was recorded only afterwards in Chapter 25.
Why relay the message through a miraculous event? It is unclear what purpose was served by miraculously opening the mouth of the donkey.
חָטָאתִי - a sincere confession? This position might read Bilam's statement as an admission of defeat more than a confession.
Did Bilam change? According to this position, though Bilam might have recognized that it was futile to curse Israel at this point, his presence on the side of the Midianites during the battle in Bemidbar 31 implies that his animosity towards Israel did not subside.
Moshe's recounting of the event – Moshe's words, "וְלֹא אָּבָּה ה' אֱלֹקיךָ לִשְמֹעַ אֶל בִלְעָּם וַיַהֲפֹךְ ה' אֱלֹקיךָ לְךָ אֶת הַקְלָּלָּה לִבְרָּכָּה ", are somewhat difficult for this approach as they imply that Bilam's plan failed and HaShem saved the nation from his machinations. Yet, according to this position, Bilam was successful in his plot to have the nation sin. As 24,000 people died as a result, it is hard to say that they were saved!
Bilam's death – The fact that Bilam is killed in the war against the Midianites, together with his partners in crime, is very fitting (Bemidbar 31:8).
Character of Bilam – This position does not merely read the later negative character of Bilam back into this story, but combines the two stories, presenting a wicked Bilam who not only seeks to harm Israel, but also actively causes Israel's downfall from the very beginning.
