Shulchan Arukh, Orach Chayim Siman 152
Can copy this into an AI, or connect the whole library to your assistant. For deeper learning, you can directly use the original seforim, sites, and apps.
אין סותרין בית הכנסת כדי לבנות בהכ"נ אחר שמא יארע להם אונס שלא יבנו האחר אלא בונים אחר תחלה ואחר כך סותרים הישן (ואפי' לא רצו לסתור רק מחיצה א' להרחיבו נמי דינא הכי (רבינו ירוחם נ"ג ח"ה וב"י בשם רמב"ם) והני מילי שהיה ראשון חזק אבל אם חרבו יסודותיו או נטו כתליו ליפול סותרים אותו מיד ומתחילין לבנות במהרה ביום ובלילה שמא תדחק השעה וישאר חרוב: הגה ואסור ליקח אבנים מב"ה הישנה כדי לבנות חדשה. (הג"א פ' ב"ה) ואסור לסתור דבר מב"ה אלא אם כן עושה על מנת לבנות: (מרדכי פ' בני העיר):
We do not destroy a synagogue in order to build another synagogue lest something befall them such that they do not build the other; rather we build the other first, and afterwards we destroy the old. (And even if they only want to destroy one wall to widen [the synagogue], this ruling applies (Rabbeinu Yerucham 53:5 and Beis Yosef in the name of the Rambam].) And this refers to if the first is strong; but if its foundations are weakened or its walls are likely to fall, we destroy it immediately, and quickly begin to build, day and night, lest time becomes pressing and it remains destroyed. Rem"a: And it is forbidden to take stones from the old synagogue to build a new one. And it is forbidden to destroy anything from the synagogue unless it done in order to build. (Mordechi - chapter "B'nei Ha'ir")