Rashi, like so many other readers of the story, wonders how God could have given the gift of prophecy to a person like Bilam who was not only a non-Israelite but not a very nice character.
One suggestion is that it was a sop to the gentiles in case they complained that if one of them had the title of prophet they could have reached the same spiritual heights as the Israelites did, but in the event when Bilam misused his gift it did not help the gentiles.
Nonetheless the rabbinic Midrash known as Sifrei claims that Bilam had the same level of prophetic ability as Moses; it is said of Bilam that he “heard the words of God and possessed the knowledge of the Most High” (Num. 24:16).
The reason why Moses is known as “the father (i.e. chief) of the prophets” is that his personal character of modesty and morality were superior to Bilam’s. A spiritual leader, prophet or otherwise, needs not only to be great in his words but in his deeds.