Why do Shuls have Mezuzahs if they don't need them?
Similar to Gershon:
I always heard that a Beis Hakenesses (בית הכנסת) doesn't need one while a Beis Hamedrash (בית מדרש) does. "Shul" is a somewhat vague term, but in most instances it refers to a Beis Medrash. This is especially emphasized by the fact that we have no problems eating (think "Kiddush") in Shul.
Anyways, it so happens to be that my Shul does not have a Mezuzah, because it is in fact a Beis Hakenesses. We also only have a "Kiddush" in a side room specifically designed for such purposes...
Then again, I may be completely wrong with all of the above. It is simply what I heard.
The Shulchan Aruch in YD 286:3 says that shuls only need a mezuzah if someone sleeps there. I don't know any shul that has an attached parsonage. Thus most if not all of our shuls are exempt.
Some may put up a mezuzah anyway either as a educational tool to teach and remind people about the mitzva of mezuzah, because some congregants may feel uncomfortable about a Jewish building not having a mezuzah, or possibly because they can raise money by allowing someone to donate the mezuzah!
I imagine it's likely the first one. Certainly no bracha should be said upon affixing it.
Alternatively, some may consider our shuls nowadays to have the status of Batei Midrash (because people often learn in them and shiurim are given in them) which the Shulchan Aruch YD 286:10 says are obligated out of doubt in mezuzah. This now seems to me like the most likely explanation.
Tosfos haRosh seems to understand that the exemption of a shuI from mezuzah stems from the laws of forced division or sale of property which does not apply to public property. Accordingly, a privately owned shul would require a mezuzah.
More about it: https://vaadmhk.org/why-my-shul-has-a-mezuzah/
You should also see that the Tur distinguishes between a beis kneses in a village vs. in a city. I suspect this is because in the old days, rural shules were more likely to be used as gathering places for other activities (other than davening).
At any rate, our shules today are used for many activities outside of prayer and therefore are not exempt.