I've heard that in Judaism, God don't just randomly appoint people to be a prophet. The prophet must be some "good" guy or pious or whatever.
If that's the case, why is balaam a prophet? He's not very righteous isn't he? Or is he?
Rashi on Numbers 22:5, s.v. "Eretz Benei Amo" ("the land of his people"), says Balaam was a special case: