A song of security, scholars suggest this was not originally meant as a pilgrimage psalm. However, it fits the theme well enough referring to the geography around the City of Jerusalem. One can hardly approach the city without climbing over at least a few mountains along the way because it sits in the midst of them.
Despite a few earthquakes now and then, the shape of Zion had never changed in the human memory. Those who trust in God are just as stable and solid. Like the mountains ringing the city, you have to get past God who watches of it.
For this reason, the psalmist is confident that no foreign invaders could permanently conquer the land. If something like that happened, there was no hope for keeping the people righteous. It would have to mean Jehovah had abandoned them.
So the psalmist prays the God would continue to protect and prosper the righteous. And if anyone in the land forsook the Covenant, let them be led away as prisoners to some other land. Thus, would the nation remain in God’s shalom.