Why did Hashem forbid Bilaam to go Moav, and then allow him, and then got angry with him for going?
(22,12) “And G-d said to Bilaam: Do not go with them. Do not curse the people because they are blessed.”
Behold, later on when Balak sent a second set of messengers Hashem said to Bilaam “If the men have come to call you, arise and go with them”, and afterwards it says that when he went with the princes of Moav “Hashem’s anger blazed because he went”. All the commentaries ask that since He said initially not to go, how could He afterwards turn around and give him permission to go? And since He gave him express permission to go, why was He angry at him?
But the explanation is that there is a difference between the word עם or עמו and between the word את or אתו. The word עם signifies equality, that both of them are doing the thing with the same intention. But the word את signifies that even though they are doing the thing together, they are not doing it with the same intention. Or even if their intention is the same, one is the doing the action and the other is being acted upon. (The word את usually signifies the person or thing that is being acted upon, for example, “and he bound את his son Yitzchok”).
Thus Hashem initially said to Bilaam “do not go עמהם”, because their intention was that he should go and curse the people, and therefore He warned him not to go with the intention to curse them - “do not curse the people because they are blessed”. But afterwards when Bilaam endeavored to be allowed to go Hashem gave him permission, but only אתם, as it says “arise and go אתם”. That is, Hashem said to him: I have already told you that you should not go עמהם - with intention to curse, but you can go אתם - with a different intention than them.
Now, had Bilaam done this Hashem would not have been angry with him at all, but due to his wickedness he did not do this. Instead “he went עם the princes of Moav” - with the same intention as them, as Rashi explains, with the intention of cursing. Therefore, “Hashem’s anger blazed against him” because he transgressed His command.
And afterwards the angel said to him “Go עם the men”, because, as Rashi explains, the way in which a person desires to go, he is led. The angel was telling him to go together with the men “because your lot is with them, and in the end you will perish from the world”. This was a measure for measure punishment - just as he wanted to be equal to them, so too would his punishment be equal to them.