The reason Jerusalem in the Word means the church in regard to its teachings is that that was the only place in the land of Canaan where the Temple was, where the altar was, where sacrifices were performed, and therefore where there was actual worship of God. That was also why the three annual feasts were celebrated there and why every male in the whole land was commanded to go there. This is why Jerusalem means the church in regard to worship and therefore also the church in regard to its teachings, since worship is defined by teachings and carried out in accord with them. It is also because the Lord was in Jerusalem and taught in its Temple and afterward glorified his human nature there.
Moreover, in the Word as spiritually understood a city means a body of teaching, so a holy city means a body of teaching based on divine truth that comes from the Lord.
We can also see that Jerusalem means a church in regard to its teachings from other passages in the Word, such as this in Isaiah:
For Zion’s sake I will not be silent and for Jerusalem’s sake I will not rest until her justice goes forth like radiance and her salvation burns like a lamp. Then the nations will see your justice and all monarchs will see your glory, and a new name will be given you that the mouth of Jehovah will utter. And you will be a crown of beauty in the hand of Jehovah and a diadem of the kingdom in the hand of your God. Jehovah will be well pleased with you and your land will be married. Behold, your salvation will come. See, his reward is with him. And they will call them a holy people, the redeemed of Jehovah; and you will be called a city sought out, not deserted. (Isaiah 62:1, 2, 3, 4, 11, 12)
This whole chapter is about the Lord’s Coming and about the new church that he is about to establish. This is the new church meant by the Jerusalem that will be given a new name that the mouth of Jehovah will utter and that will be a crown of beauty in the hand of Jehovah and a diadem of the kingdom in the hand of God, with which Jehovah will be well pleased, and which will be called a city sought out, not deserted. This cannot mean the Jerusalem where Jews were living when the Lord came, because this was the opposite in all respects, more properly called “Sodom,” as it is in Revelation 11:8, Isaiah 3:9, Jeremiah 23:14, Ezekiel 16:46, 48.
Another passage from Isaiah:
Behold, I am creating a new heaven and a new earth; the former ones will not be remembered. Be glad and rejoice forever in what I am creating. Behold, I am going to create Jerusalem as a rejoicing and her people as a gladness, so that I may rejoice over Jerusalem and be glad about my people. Then the wolf and the lamb will feed together; they will do no evil in all my holy mountain. (Isaiah 65:17, 18, 19, 25)
from The Lord, Section 65