The ubiquitous practice of lighting Chanukah neiros in shul between mincha and ma’ariv finds its source in the Rishonim and is codified in Shulchan Aruch (Orach Chaim 671:7). The Mechaber, in the middle of a discussion regarding the correct placement of the Menorah in, or outside, of one’s house, states, “And in the Beis HaKnesses, one places it by the southern wall, and we light and bless on it for pirsumei nisa.” Elaborating on this minhag, the Rema adds that one does not fulfill his obligation to light Chanukah neiros through this hadlakah; one must return home and light again.
In the Beis Yosef (ibid.) the Mechaber brings two sources for this practice. He first suggests that lighting Chanukah neiros in shul was instituted for the sake of guests who do not have a house to light in, just as Chazal instituted Kiddush in shul on Friday night to accommodate the guests who eat, drink, and sleep there. The Beis Yosef states that the Kol Bo (Siman 44) offers such an approach. There are a few questions here: If the Beis Yosef means to refer to guests who do not sleep in the shul, they should light wherever they are spending the night, alongside their hosts, not in the shul. If the guests are sleeping in the shul, why do they not light the Menorah themselves? Furthermore, the Kol Bo himself does not actually say that the practice was instituted for the sake of guests. Instead, he writes that the neiros are lit to be motzi those who are not baki or zariz, which raises an obvious and serious issue: how can the obligation to light be fulfilled by those who are either not baki or zariz outside the auspices of a home, when the Halacha clearly mandates lighting in a bayis?