Hashem Fixing Bilam's Words
בפסוק וישם ה' דבר בפי בלעם דרשו חז"ל שנתן רסן לתוך פיו כו' ע"ש וי"ל כי שימה הוא לשון סידור כמו ושמו כו' איש על עבודתו
On the verse "And Hashem placed a word in Bilam's mouth" (Bamidbar 23:5), Chazal expounded that He set a bridle into his mouth, and so on (see there). And one may suggest that "placing" (vayasem) is a term denoting arrangement and ordering, as in "and they set (vesamu) each man over his service."
The Sfas Emes opens with Chazal's reading that Hashem put a bridle in Bilam's mouth, and adds that the word vayasem means Hashem arranged and ordered the words precisely, the way men are assigned to their appointed tasks.
והנה כל כחו של אותו רשע הי' להיות כלי מוכן לרעה
Now, the entire strength of that wicked one was to be a vessel prepared for evil.
Bilam's whole power lay in his readiness to serve as an instrument for evil purposes.
וכמו שהצדיקים יכולין לשנות דברי נבואתם מרעה לטובה כי הכל תלוי במקבלי הנבואה כמו שיש טעמים בכל הדברים
And just as the tzaddikim are able to change the words of their prophecy from evil to good, since everything depends upon the ones who receive the prophecy, just as there are te'amim (cantillation notes that carry meaning) in all things,
Tzaddikim can steer a prophecy from a harsh outcome to a good one, because the meaning hinges on the receiver — much as the cantillation notes shape how a phrase is understood.
שהטעם מהפך פי' הדיבור כידוע
for the ta'am (note) reverses the meaning of the word, as is well known,
A single ta'am can flip the sense of a word entirely, a well-known principle that the Sfas Emes uses as his model.
כן הרשע רצה לפרש הדברים לרעה כמ"ש ודבר מה יראני והגדתי לך פי' שימשוך המראה לטובת בלק
so too this wicked one wished to interpret the words for evil, as it is written, "and whatever He shows me I will tell you" (Bamidbar 23:3) — meaning that he would draw the vision toward Balak's benefit.
Bilam similarly tried to bend the words toward evil, intending to channel the vision he received to Balak's advantage.
אך הקב"ה סידר הדברים שלא יוכל לעקום פיו ולשונו כלל
But the Holy One, Blessed is He, arranged the words in such a way that he could not twist his mouth and tongue at all.
But Hashem set the words in place so firmly that Bilam had no room to twist them with his mouth or tongue.
והרשע הבין זאת
And the wicked one understood this.
Bilam himself recognized that he had been locked out of any ability to distort the message.
ולכן אמר ברך לקחתי וברך ולא אשיבנה שראה שלא יוכל לשנות הדברים כלל
Therefore he said, "I have received a blessing, and He has blessed, and I cannot reverse it" (Bamidbar 23:20) — for he saw that he could not change the words at all.
This is why he admitted he had received a blessing he could not reverse — he saw plainly that the words were beyond his power to alter.
וכן רמזו חז"ל בפסוק וטעם זקנים יקח על בלק ובלעם שניטל מהם בחי' הטעמים כנ"ל:
And so too Chazal hinted in the verse "and the ta'am (discernment) of elders He took away" regarding Balak and Bilam, that from them was removed the aspect of the te'amim, as explained above.
Chazal allude to this when they say discernment was taken from the elders: the te'amim, the power to shift meaning, were stripped from both Balak and Bilam.
Summary: The Sfas Emes reads vayasem, "Hashem placed a word in Bilam's mouth," as Hashem arranging and ordering the words so precisely that Bilam could not tamper with them. He explains that prophecy depends on its receiver, and that just as the te'amim, the cantillation notes, can reverse the meaning of a word, a tzaddik can turn a prophecy from evil to good. Bilam, a vessel prepared for evil, wished to bend his vision toward Balak's benefit, but the Holy One, Blessed is He, set the words so that he could not twist his mouth or tongue at all. Bilam recognized this and confessed that he had received a blessing he could not reverse. Chazal hint at this in the verse that the ta'am of elders was taken away: the power to shift meaning was removed from both Balak and Bilam.