The Gemara discusses the prohibition against using a synagogue as a "Kapandria" – a shortcut. This means that one may not cut through a synagogue in order to shorten his route when walking. This prohibition is codified by the Shulhan Aruch (Orah Haim 151:5). Some explain that this is forbidden because it is disrespectful to the synagogue, whereas others explain that since a synagogue is designated for Misva purposes, it is forbidden to use it for the mundane purpose of shortening one’s trip.
There is, however, one important exception to this rule. Namely, if one entered the synagogue to pray or to learn, then he is permitted to leave from a different door than the one he used to enter in order to shorten his trip back home or wherever he is going. Since he used the synagogue for the purpose of praying and learning, he may then use the most convenient exit, and he is not considered to be using the synagogue as a shortcut. In fact, the Mishna Berura (Rav Yisrael Meir Kagan of Radin, 1839-1933) adds that it is a Misva to exit the synagogue from a different door than the one used to enter. In the times of the Bet Ha’mikdash, visitors would enter through one gate and then exit through in order, so that the Bet Ha’mikdash would not become dull, and the experience of visiting would remain exciting. By the same token, then, there is a special Misva to enter the synagogue through one door and then exit through another.
The Poskim debate the question of whether one may use the synagogue as a shortcut, but stop in the synagogue for a few moments and recite a chapter of Tehillim. The Ben Ish Hai (Rav Yosef Haim of Baghdad, 1833-1909) writes that this is permissible, and thus one who wishes to cut through a synagogue may do so if he reads a chapter of Tehillim or even just sits for a few moments in the synagogue, which is in itself a Misva. Preferably, the Ben Ish Hai writes, one should do both – sit for a few moments, and recite Tehillim. Since the person used the synagogue for a Misva, it is permissible to use it a shortcut. This is also the ruling the Bi’ur Halacha (essays accompanying the Mishna Berura).
Hacham Ovadia Yosef, however, in his Halichot Olam, and as cited by his son, Hacham David Yosef, in Halacha Berura, disagrees. He maintains that it is only when one’s primary intention is to pray or learn in the synagogue that he is then allowed to leave through the door which shortens his walk back home. But one may not plan to use the synagogue as a shortcut, even if he spends a few moments in the synagogue reciting Tehillim.
Another question arises in the case where people wish to cut through the sanctuary in order to get to a different room for prayers or Torah study. Is it permissible to cut through a synagogue for the purpose of a Misva?
The Bi’ur Halacha cites the ruling of the Peri Megadim (Rav Yosef Teomim, 1727-1793) that cutting through a synagogue for a Misva purpose is permissible. However, the Bi’ur Halacha himself disagrees. He notes the formulation of the Rambam (Rav Moshe Maimonides, Spain-Egypt, 1135-1204) in presenting this Halacha, which implies that only if one enters the synagogue for a Misva purpose is he then allowed to leave through the most convenient exit, since his initial entry into the synagogue was for a Misva. This does not mean that one can from the outset cut through a synagogue in order to perform a Misva.
There are those who suggest that even according to the stringent view of the Bi’ur Halacha, it would be permissible to cut through a synagogue for the purpose of going to a different room when a Minyan is held to pray. Since the person is on his way to pray – which is, of course, the primary purpose of a synagogue – it is acceptable to cut through a synagogue. This is analogous to the case addressed by the Magen Abraham (Rav Abraham Gombiner, 1633-1683) of one who uses a Sefer (book of Torah literature) as a stand, to prop up the Sefer which he wishes to read. The Magen Abraham writes (in Siman 154) that although generally one may not use a Sefer in this manner, as a stand, this might be allowed if it is used to facilitate learning of a different Sefer. By the same token, perhaps, we can argue that cutting through a synagogue to reach a different room of prayer is not disrespectful to the synagogue, since he uses the synagogue as a shortcut to the place where he will pray.
In any event, different views exist in this regard, and so it is preferable not to cut though a synagogue to go to a different room where one wishes to pray, especially if different routes are available. Certainly, though, one must ensure not to cut through a synagogue for a different purpose.
This entire discussion underscores the Kedusha of synagogues and the importance of treating them with the utmost respect and reverence.
Summary: It is forbidden to use a synagogue as a shortcut. However, if one goes to the synagogue for prayer or study, he may then leave the building through the most convenient exit. In fact, it is a special Misva to leave the synagogue through a different door than the one through which one had entered. One may not use the synagogue as a shortcut even if he stops for a few moments in the synagogue to recite Tehillim. It is questionable whether one may cut through the sanctuary in order to reach a different room in the building where he wishes to pray, and it is preferable to be stringent in this regard.