Rabbi Reisman points out that Ramban states that Balaam was not really a navi, but was attempting to use his magic to set himself up as one. Hashem's reaction to this was to give him the opportunity to raise himself to the highest level that he could. Balaam refused to take advantage of the opportunities that he was given and at each choice, was given a chance at the lower level that he reached.
Rav Hirsch among others explains that if someone insists on trying to disobey Ahashem's will, Hashem will allow him to destroy himself. For example, in the explanation of Balak 22:12-13 Rav Hisrch points out
12
Now had Balaam been a prophet of the Truth he would faithfully have
transmitted this declaration of Hashem to the envoys of Balak and the
purpose of Hashem's intervention would have been achieved without the
whole following episode. Balak, andMoav, instead of fearing the
attacking and conquering might of this People, would have been induced
to know the moral factor which was innate in it to which Hashem had
promised His blessing and to befriend them to their own advantage.
But
13
Balaam suppressed the second part, the really essential part of
Hashem's warning. He just speaks in general terms מאן השם, which
forthwith allows it to be understood tat he himself would be pleased
to curse the people, only מאן השם לתתי להלוך עמכם, the Hashem Whose
prophet I am does not finnd it befitting for me to go with you.
After all, they were only, as remarked above, זקני מואב not שרי מואב,
only plebeans, not really princes.
As a result of this,
Balak knew his man and did not let himself be put off from his by the
first refusal
As a result of Balaam attempting to work around Hashem, Hashem says, that if it for your personal honor that they came for you, go ahead and try to go with them. However, do not forget that you were categorically forbidden to curse the Bnai Yisrael, even though you hid that from Moav.
20
We have already remarked on verses 16 &
17
that Balak's request had two points (a) that Balaam come at his
invitation and (b) that he curses Israel. For the first part he was
given permission, regarding the second part, whic constituded the real
intended purpose of Balak, it had in verse 12, already at the first
mission had been peremptorily denied to him.
As we see, Hashem is telling Balaam that if he insists on going, he will only be able to convey the blessing, the exact opposit of what Balak inteds.
The question now arises, why was Hashem angry? The reason given by Rav Hisrsch is that while Balaam was given permission to go with the messengers (אתם) he actually went with the intention to somehow bring about their purpose.
22
not כי הלך that he went with Balak's messengers, ... But he did not
just go with them, הולך הוא, he was "goer" with them, one striving to
reach his own end. In spite of the definite warning he had received
from Hashem, his mind was still obscured by the obsession that he
would be able to achieve the purpose so desired by Balak and himself.
As a result, the מלאך is sent to point out the result of what he is attempting to do. It is actually a final attempt to show mercy to Balaam and get him do do teshuvah.