The verse itself originates with Balaam in Bamidbar 24:5, and the Gemara in Sanhedrin 105b explains its entry into Jewish consciousness: Rabbi Yochanan teaches that from Balaam's blessing you can discern what was in his heart — he sought to say that Israel would have no synagogues or study halls, but instead he uttered "How goodly are your tents, Jacob," which became a blessing on those very institutions.
The connection between the verse and entering sacred space is made explicit by Sanhedrin 105b, which notes that Rabbi Abba bar Kahana adds that all of Balaam's blessings eventually reverted to curses — except for the blessing of synagogues and study halls — making "mah tovu" uniquely permanent among his words, a natural candidate for recitation upon entering those spaces.
the Shelah HaKadosh (Shenei Luchot HaBerit, Balak) develops the verse's liturgical resonance further, noting that Chazal read "your tents" as referring to Israel in its peaceful settlement and "your dwellings" as applying even in periods of destruction and ruin, so that the verse spans every condition of Israel's existence — precisely the breadth that makes it fitting as a daily opening prayer.
the Kedushat Levi (Bamidbar, Balak:24) adds an inward dimension: "Yaakov" names Israel at a spiritually lower ebb, while "Israel" names it at its highest, and "tents" (אהל, a temporary abode) represents Torah study as an occasional activity while "dwellings" (משכן, a permanent structure) represents Torah as a fixture of daily life — an interpretation that reinforces why the verse opens the morning prayer with an aspiration toward that higher, permanent engagement.