As I see them from the mountain tops,
Gaze on them from the heights,
There is a people that dwells apart,
Not reckoned among the nations,
As Rashi below explains -
כי מראש צורים אראנו FOR FROM THE TOP OF THE ROCKS I SEE HIM — I look at their origin and at the beginning of their root (descent), and I behold them strongly founded as younder rocks and mountains through their ancestors and ancestresses..
And behold, the sages of Israel teach -
אמר רבי יוחנן מברכתו של אותו רשע אתה למד מה היה בלבו
Rabbi Yoḥanan says: From the blessing of that wicked person, Balaam, you can ascertain what was in his heart.
Based on the above teaching, we must understand what was in the heart of Bilaam that he chose to curse Israel with the following statement - "As I see them from the mountain tops, Gaze on them from the heights"
There is what to say based on the teaching of the Holy Shl'a (Yeshayahu ben Avraham Ha-Levi Horowitz (Hebrew: ישעיה בן אברהם הלוי הורוויץ), (c. 1555 – March 24, 1630) on the below verse -
His question above is the following - This verse seems to be one of comfort and assurance. However, in this chapter, we are in the middle of the curses that will befall Israel, and we have not finished that yet, and in the middle, where is there room to insert this random verse that seems like a blessing and comfort?
And I have received/understood that this verse too is included in the aspect of rebuke and shame, as there is a great difference between a wicked man, the son of a wicked man who is a sinner than a wicked man who is the son of a righteous man, as the punishment for a wicked man who has a righteous father is greater than the wicked son of the wicked. This is because he saw his father behave in a righteous and kind manner, and the ways of his ancestors aren't currently within his reality. And similarly there is a difference in scenarios when one is dwelling in a lowly level than one who is dwelling in a place of Torah.
On this the verse is really saying - "I will recall these matters for the purpose of holding it against you! That you are from the holy seed of the founding fathers of Israel, Abraham, Isaac and Jacob, and the land I will recall as well, since I gave you the land of Israel, and the land of Israel makes someone by default wiser (As we see below)"
רַבִּי זֵירָא שְׁמַע מִינַּהּ אַוֵּירָא דְּאֶרֶץ יִשְׂרָאֵל מַחְכִּים
Rabbi Zeira said: Conclude from this incident that the air of Eretz Yisrael makes one wise
And with all of this, you still did not go in the path of the straight, therefor everyone shall place within their heart, especially those that had ancestors who feared the heavens, even one who is sitting amongst wise scholars learned with Torah, you must try diligently to go in their footsteps, in regard to study of Torah, their actions, and their attributes, and to go in the ways of the favorable ones.
And this is what Bilaam the wicked was saying - "As I see them from the mountain tops, Gaze on them from the heights,"
As Rashi had explained that he was recalling their patriarchs and matriarchs, and he was trying to bring an evil eye on Israel that they were not following the footsteps of their holy patriarchs and matriarchs. And because of that, their punishment should be greater!
And it was a tremendous act of kindness that The Holy One Blessed Be He, that the curses of Bilaam were flipped into Blessings!