The Shulchan Aruch · Orach Chayim
אורח חיים ק״נOrach Chayim 150
Siman 150 of 697 in Orach Chayim — 5 se'ifim
הלכות בית הכנסתLaws of the Synagogue· siman 150
Se’if 1א׳
כּוֹפִין בְּנֵי הָעִיר זֶה אֶת זֶה לִבְנוֹת בֵּית הַכְּנֶסֶת וְלִקְנוֹת לָהֶם תּוֹרָה נְבִיאִים וּכְתוּבִים. וְעַיֵּן לְעֵיל סי' נ"ה אִם כּוֹפִין זֶה אֶת זֶה לִשְׂכֹּר לָהֶם מִנְיָן.
The Building of a Synagogue and that it Should be Tall. Containing 5 S'ifim: The residents of a city may compel one another in order to build a synagogue and to buy a Torah, Prophets, and Writings. (And see above, siman 55, s'if 22 [regarding] if they may compel one another to hire a quorum for themselves.)
Se’if 2ב׳
אֵין בּוֹנִים בֵּית הַכְּנֶסֶת אֶלָּא בְּגָבְהָהּ שֶׁל עִיר, וּמַגְבִּיהִין אוֹתוֹ עַד שֶׁיִּהְיֶה גָּבוֹהַּ מִכָּל בָּתֵּי הָעִיר שֶׁמִּשְׁתַּמְּשִׁים בָּהֶם, לַאֲפוּקֵי בִּירָנִיּוֹת (פֵּרוּשׁ בִּנְיָנִים הָעֲשׂוּיִם לְנוֹי תַּרְגּוּם שְׂכִיּוֹת הַחֶמְדָּה בִּירָנִיּוֹת שַׁפִּירָן) וּמִגְדָּלִים שֶׁאֵין מִשְׁתַּמְּשִׁים בָּהֶם; וְגַג שֶׁהוּא מְשֻׁפָּע וְאֵינוֹ רָאוּי לְתַשְׁמִישׁ, מְשַׁעֲרִין עַד הַמָּקוֹם שֶׁהוּא רָאוּי לְתַשְׁמִישׁ, דְּהַיְנוּ שֶׁאִם יֵשׁ עֲלִיָּה תַּחַת הַגַּג לֹא תְּהֵא גָּבוֹהַּ יוֹתֵר מִבֵּית הַכְּנֶסֶת. הַגָּה: וּבִשְׁעַת הַדַּחַק, אוֹ שֶׁיֵּשׁ מִצְוַת מַלְכוּת שֶׁאֵינָן רַשָּׁאִים לִבְנוֹת בֵּית הַכְּנֶסֶת כְּדִינוֹ, מֻתָּר לְהִתְפַּלֵּל בְּבַיִת אַף עַל פִּי שֶׁדָּרִין בַּעֲלִיָּה עַל גַּבָּיו, וּבִלְבַד שֶׁיִּנְהֲגוּ בָּעֲלִיָּה שֶׁעָלָיו בִּנְקִיּוּת, כְּמוֹ שֶׁיִּתְבָּאֵר סוֹף סִימָן קנ"א. (בֵּית יוֹסֵף סִימָן קנ"ד בְּשֵׁם מַהֲרִ"י בֶּן חָבִיב).
When we build a synagogue, it should only be at the height of the [rest of the] city, and we heighten it until it is taller than the buildings of all [other] buildings that are in use up to [but not including] the ends of the spires(i.e., structures used for ornamental purposes; Targum [Yonatan] for delightful imagery (Isaiah 2:16): decorative spires) and towers that are not used. A slanted roof that is not usable: we measure it from the part that is fit to usable, that is, if there is an attic under the roof, it should not be higher than the synagogue. Gloss: In an extenuating circumstance, or if there is fear of the [secular] regime that doesn't give permission to build a synagogue according to its [i.e. Jewish] law, then it is permitted to pray in a house, even though someone lives in the attic above it, as long as those living in the attic above it keep it clean, as will be explained at the end of siman 151 (Beit Yosef - siman 154 in the name of Mahari b. Chaviv).
Se’if 3ג׳
מִי שֶׁהִגְבִּיהַּ בֵּיתוֹ יוֹתֵר מִבֵּית הַכְּנֶסֶת, יֵשׁ אוֹמְרִים שֶׁכּוֹפִין אוֹתוֹ לְהַשְׁפִּילוֹ. וְאִם עָשָׂה בִּנְיָן גָּבוֹהַּ יוֹתֵר בְּקֶרֶן אֶחָד מִבֵּית הַכְּנֶסֶת, סַגֵּי בְּכָךְ (הַגָּהוֹת מַיְמוֹן פֶּרֶק י"א מֵהִלְכוֹת תְּפִלָּה, שֶׁכֵּן הָיָה מַעֲשֶׂה).
If one built up one's house higher than the synagogue, there are those who say that that we compel [that person] to lower it. (And if one made the structure in [just] one corner of the synagogue taller [than other buildings], that is sufficient) (Hagahot Maimon - chapter 11 of the Laws of Prayer; for there was such a case).
Shulchan Aruch, Orach Chayim — Torat Emet 363 edition, via Sefaria — public domain
English: Sefaria Community Translation — CC0