I believe God used Balaam to accomplish what needed to be accomplished. His was just a mouthpiece, nothing more. Balaam wasn't a teacher of righteousness. Quite the opposite actually.
Revelation 2
14 But I have a few things against thee, because thou hast there them that hold the doctrine of Balaam, who taught Balac to cast a stumblingblock before the children of Israel, to eat things sacrificed unto idols, and to commit fornication.
From what I understand, fornicators and idolaters will not enter the Kingdom of Heaven. That goes double for those who teach such things. Correct me if I'm wrong.
Peter numbers Balaam with those who will be destroyed because their unrighteous ways.
2 Peter 2
15 Which have forsaken the right way, and are gone astray, following the way of Balaam the son of Bosor, who loved the wages of unrighteousness;
16 But was rebuked for his iniquity: the dumb ass speaking with man's voice forbad the madness of the prophet.
17 These are wells without water, clouds that are carried with a tempest; to whom the mist of darkness is reserved for ever.
The Lord used a lying spirit. Because the Lord used him, does that make the spirit righteous?
2 Chronicles 18
20 Then there came out a spirit, and stood before the Lord, and said, I will entice him. And the Lord said unto him, Wherewith?
21 And he said, I will go out, and be a lying spirit in the mouth of all his prophets. And the Lord said, Thou shalt entice him, and thou shalt also prevail: go out, and do even so.
The Lord also used Judas.
The Lord right now is using the iniquity of the world to accomplish what must be accomplished before the return of Christ. I know people don't like hearing that, but it's true.