A host of meforshim comment on and struggle to understanding how Hashem could first tell Bilam not to go with the messengers of Balak, then OK his going, and then get angry that he went.
Rashi (on "kiholeichhu") implies that Hashem's anger was directed not at Bilam's going with the messengers, but at the fact that "nisavahla'leches," he was consumed by the desire to go (see Seforno, Rashbam as well), he acted like a ba'altayvaabout it. If I had to sum up Rashi in a nutshell, I would say that Bilam's actions here reveal him to be a mumar l'teyavon, he had a tayva for evil, he wasn't just a mumar l'hachis, someone intellectually or philosophically misguided. Hashem's response to Bilam's request essentially was, "Nebach, if you want to go, then go." It didn't call for his jumping out of bed first thing in the morning to get an early start, his skipping along the road and whistling a happy tune while travelling. By way of analogy, in our neighborhood on ta'aneisim we have restaurants galore open. One of one of my wife's pet peeves is the fact that these places are far from starving for business on those days; for some people, there is no sense of embarrassment in having a lunch on a ta'anis. The halacha certainly allows people to eat for various reasons, but if you have to do so, do it b'tzin'ah, privately -- don't parade down main street sipping your Starbucks ice coffee.
The gemara (San. 102b) tells us that RavAshi once gave a shiur and mentioned "Menashe, our friend." That night King Menashe appeared to him in a dream, upset at RavAshi for having called him "friend," as if they were equals. "Had you been alive when I was," said Menashe, "Not only would you have worshipped avodahzarah, but you would have lifted the tails of your bekeshe so you could run after it faster."
Maharal explains that there are two types of sinners. There are those who sin, but who know what they are doing is wrong. They are aware of their own weakness,and therefore try their best to avoid situations that they know will lead to trouble. The drunk knows that if he walks home past the pub, he may not make it home, so he looks for reasons to take a different route. He welcomes getting a ride from a friend, he welcomes when they are doing construction on that road and he is forced to head some other way. True, many times he winds up in the pub, but if there is an obstacle in his way, he breathes a sigh of relief. Not so the person so caught up in aveiros that he doesn't even see that what is is doing is wrong. Not only does not not welcome obstacles, he does everything in his power to remove them.
Menashe was telling RavAshi -- I knew what I was doing was wrong; I at least let down the tails of my bekeshe in the hope that maybe I would trip myself up and thwart myself at least temporarily from that avodah zarah. Had you been there, aderaba, you would have not even have tried to stop yourself.
Bilam perhaps can't be blamed for going to Balak, but why did he have to lift up the tails of his bekeshe and run to get there?
The Alter of Slabodka is quoted as saying that mussar may not stop someone from doing wrong, but they will certainly enjoy the aveirah less. The story of Bilam tells us that this isn't just stam a vort, but there is real truth to it -- there is a din v'cheshbon on hana'ah aside from the act itself.
There are many other views in the Rishonim and Achronim to explain what appears to be a change of mind by Hashem and what Bilam did wrong. Ramban suggests that Bilam should have made clear that his going was conditional on his speaking only the words Hashem allowed. His not mentioning that stipulation gave the perception that he had been given free reign by Hashem to curse Bnei Yisrael, creating a chilulHashem. Ibn Ezra seems to deny the problem completely -- Bilam is punished for going even though Hashem granted permission. Hashem grants free will and allowed Bilam to go in spite of his (Hashem's) disapproval. However, Bilam suffers the consequences of his own choice. (Ibn Ezra quotes another interesting answer from Sad Gaon -- take a look.) Many meforshim contrast Hashem's directive to go "itam," with the messengers, but with a separate agenda, with Bilam's going "imam," along with them, sharing the same agenda.
The SefasEmes (as usual) has a very striking and original approach. After Hashem's denial of his first request to go, Bilam is contrite. He tells the messengers of Balak that he is powerless to go against Hashem's wishes. However, he begs them to remain another night lest things change. And things do -- Hashem grants his wish to go. What caused the difference in response? SefasEmes explains that it was Bilam's acknowledgement of his own smallness -- his hisbatlus! Don't we ask in our tefilos for Hashem to change from midashadin to midasharachamim? As many explain, Hashem doesn't change -- we change. Bilam changed as well -- at least for the moment,he acknowledged his own limitations. The problem is that he did so temporarily, and only as a means to advance his own agenda.
If a rasha like Bilam could advanced his own agenda by, at least for a moment, acknowledging his own nothingness, kal v'chomer what we could achieve if we internalized the feeling of hisbatlus k'lapei shemaya.