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; But was rebuked for his iniquity: the dumb ass speaking with man's voice forbad the madness of the prophet.
Numbers 22:21-30
And Balaam rose up in the morning, and saddled his ass, and went with the princes of Moab. And God's anger was kindled because he went: and the angel of the LORD stood in the way for an adversary against him... And the ass said unto Balaam, Am not I thine ass, upon which thou hast ridden ever since I was thine unto this day? was I ever wont to do so unto thee? And he said, Nay.
Peter invokes the Numbers 22 Balaam-and-talking-donkey narrative as the constitutional precedent for the madness of false-prophet-for-hire conduct. The Numbers 22 account records the divine rebuke of Balaam's avarice through the donkey's speech — a dumb animal rebuking the prophet's madness. Peter applies this Numbers 22 precedent to the false teachers: their way is Balaam's way (mercenary prophecy), and the same divine rebuke that used a donkey to stop Balaam will stop them.