Selling Shuls
(ח) וְעָ֥שׂוּ לִ֖י מִקְדָּ֑שׁ וְשָׁכַנְתִּ֖י בְּתוֹכָֽם׃
(8) And let them make Me a sanctuary that I may dwell among them.
גמ׳ בני העיר שמכרו רחובה של עיר אמר רבה בר בר חנה אמר רבי יוחנן זו דברי ר' מנחם בר יוסי סתומתאה אבל חכ"א הרחוב אין בו משום קדושה
GEMARA: The mishna states: Residents of a town who sold the town square may purchase a synagogue with the proceeds. Concerning this mishna, Rabba bar bar Ḥana said that Rabbi Yoḥanan said: This is the statement of Rabbi Menaḥem bar Yosei, cited unattributed. However, the Rabbis say: The town square does not have any sanctity. Therefore, if it is sold, the residents may use the money from the sale for any purpose.
ור' מנחם בר יוסי מאי טעמיה הואיל והעם מתפללין בו בתעניות ובמעמדות ורבנן ההוא אקראי בעלמא:
And Rabbi Menaḥem bar Yosei, what is his reason for claiming that the town square has sanctity? Since the people pray in the town square on communal fast days and on non-priestly watches, it is defined as a place of prayer and as such has sanctity. And the Rabbis, why do they disagree? They maintain that use of the town square is merely an irregular occurrence. Consequently, the town square is not to be defined as a place of prayer, and so it has no sanctity.
בית הכנסת לוקחין תיבה: אמר רבי שמואל בר נחמני א"ר יונתן לא שנו אלא בית הכנסת של כפרים אבל בית הכנסת של כרכין כיון דמעלמא אתו ליה לא מצו מזבני ליה דהוה ליה דרבים
§ The mishna states: If they sold a synagogue, they may purchase an ark. The Gemara cites a qualification to this halakha: Rabbi Shmuel bar Naḥmani said that Rabbi Yonatan said: They taught this only with regard to a synagogue of a village, which is considered the property of the residents of that village. However, with regard to a synagogue of a city, since people come to it from the outside world, the residents of the city are not able to sell it, because it is considered to be the property of the public at large and does not belong exclusively to the residents of the city.
אמר רב אשי האי בי כנישתא דמתא מחסיא אף על גב דמעלמא אתו לה כיון דאדעתא דידי קאתו אי בעינא מזבנינא לה
Rav Ashi said: This synagogue of Mata Meḥasya, although people from the outside world come to it, since they come at my discretion, as I established it, and everything is done there in accordance with my directives, if I wish, I can sell it.

אקראי בעלמא - אינו תדיר:

because the town square is not normally used for prayer it does not attain any sanctity therefore if you sell the town square the proceeds may be used for anything
טורסיים - צורפי נחושת:
there name wasn’t copper-finer but really their occupation was to refine copper
כיון דמעלמא קאתו לה - נראה לפרש הכי כיון שרוב בני אדם רגילים ללכת שם להתפלל אף על פי שאין נותנים כלום בבנינו מכל מקום כיון דלדעת אותן רבים נעשה חמורה קדושתו ואינן יכולין למוכרו ועוד יש לפרש כיון שרבים נותנים בבנינו ובשאר צרכיו ובסמוך נמי דקאמר רב אשי דאדעתא דידי קאתו היינו ממה שנותנים בו לעשות רצונו:

since people come to it from the out side world it appears to be understood as follows since most people are accustomed to going there to daven even though they do not contribute to its building since it constructed for the masses its holiness is dealt with strictly and may not be sold

(ז) והא דב"ה נמכר הני מילי של כפרים שאין באים אנשים ממקומות אחרים שלא נעשית אלא לבני הכפרים לבדם (ואפי' בנו אותם משל אחרים) (מרדכי ישן בשם ראבי"ה) אבל של כרכים שבאים שם ממקומות אחרים אפילו בנו אותו משלהם אינו נמכר אא"כ תלו אותו בדעת היחיד שאז יעשה בו היחיד מה שירצה בהסכמת הצבור וה"ה לכל דברי קדושה שנזכרו כאן דכולהו גרירי בתר בית הכנסת: הגה יחיד שבנה ב"ה ונתנה לקהל דינה כב"ה של קהל

(In halacha 6 he discusses that in order to support talmudic or marrying off orphans you can sell a Shul). In 7 he says

when can a shul be sold, when people aren’t coming from other places( even if it was built with other peoples money) … however in a larger village where people come from other places then even if it was built from their own money it can’t be sold unless you put the entire sale of the decision of the shul on one individual(when it was built it was built with the da’as that the decision is left up to this one guy) but if one man builds a shul and then gives it to the community then he doesn’t have the right to sell it. (main distinction: a shul where visitors come they have a say in the sale of the shul so if they are in another city they may not agree with the sale and t/f it can’t be sold)

והיינו כשמכרו בני העיר שלא מדעת פרנסיהם - נראה דדוקא אם יש טובים בעיר אז אמרינן דאין רשות לבני העיר על מכירה זו בשלמות אבל אם לא נתמנו טובים בעיר אז מועילה המכירה שלהם לגמרי כמו זט"ה במעמד אנשי העיר וכן נראה מחידושי הרשב"א על מגילה עי"ש:

באור הלכה
in a city where there is good you would need the permission of the entire city for it to be a good sale but if theres nothing good in the city then you just need the 7 good men in the city for it t be a good sale and we see that the same happened in chidushei harashba on megila.

שבאין שם וכו' - ר"ל ועשו אותו בודאי ג"כ אדעתא דכו"ע. כתב מגן אברהם בשם המבי"ט דבית החיים יכולים למכור:

when they made the shul they made it with the knowledge that it would be for everyone. then the Magen Avraham in the name of the mabeet says that you could sell a cemetery.