A Midrash explained that the Torah records Balaam's story to make known that because the nonbeliever prophet Balaam did what he did, God removed prophecy and the Holy Spirit from nonbelievers. The Midrash taught that God originally wished to deprive nonbelievers of the opportunity to argue that God had estranged them. So in an application of the principle of The Rock, His work is perfect; for all His ways are Justice, God raised up kings, sages, and prophets for both Israel and nonbelievers alike. Just as God raised up Moses for Israel, God raised up Balaam for the nonbelievers. But whereas the prophets of Israel cautioned Israel against transgressions, as in Balaam sought to breach the moral order by encouraging the sin of Baal-Peor in And while the prophets of Israel retained compassion towards both Israel and nonbelievers alike, as reflected in and Balaam sought to uproot the whole nation of Israel for no crime. Thus God removed prophecy from nonbelievers.