And Hashem opened the eyes of Bilam, and he saw the angel of Hashem standing in the way, and his sword drawn in his hand; and he bowed and prostrated himself on his face.
Midrash Tanchuma Balak 9 — the animal was granted perception that would derange a human.
Sefaria — Rashi on 22:23 (parallel)
English: “And the donkey saw the angel of Hashem” — but Bilam did not see. Why did the Holy One grant an animal greater perception than a man? Because a man’s mind is settled upon him; if he saw destructive spirits he would go mad.
Theological reason for differential vision of angelic threat.
Opening Bilam’s eyes is a controlled revelation — the donkey saw first so that the prophet’s pride would be broken by an animal’s clearer sight.