The Gemara in Masechet Shabbat states that it is permissible to instruct a non-Jew to perform a Melacha D’Oraita (an act prohibited by Torah law) on Shabbat for the purpose of performing a Brit Milah or purchasing land in Eres Yisrael. The Halacha allows asking the non-Jew, which is a Rabbinic prohibition, for the sake of accomplishing these two Misvot of the Torah.
Most Rishonim (early authorities) understand that the Misvot of Brit and Eres Yisrael are the only two exceptions, because of their unique status in Halacha. Accomplishing other Torah Misvot would not override the Rabbinic prohibition of Amira L’Akum, instructing a non-Jew to violate Shabbat. However, there is the lone opinion of the Itur (Rabbi Yishak ben Abba Mari, 1122-1193, France) that holds that the two Misvot brought in the Gemara are only examples, and in fact, performance of any Torah Misva justifies instructing a non-Jew to violate any Torah prohibition on Shabbat.
Maran clearly does not rule in accordance with the Itur. He only brings the Misvot of Milah and Eres Yisrael. Even the Rama (276), who does cite the Itur, only does so to justify common practice and restricts relying on him to "Sha’at HaDachak" (extenuating circumstances), such as a wedding.
Therefore, there is clearly no basis to ask a non-Jew to turn on lights in the Bet Knesset, even for the purpose of enabling prayer and Torah study. Unfortunately, this is rampant in many synagogues. People think that whatever a Jew cannot do on Shabbat, the non-Jew can. This is not a way to run a Bet Knesset.
In a "Sha’at HaDachak" (extenuating circumstances) after the fact there are precedents for relying on the Itur. For example, there was a case in Egypt, in which the lights in the Bet Knesset were extinguished on the night of Yom Kippur. As there was absolutely no alternative, and there was no way for the people to pray on that holy night, the Chief Rabbi, Rabbi Refal Ankova, instructed a non-Jew to turn on the lights.
On the other hand, the Hatam Sofer did not permit using a non-Jew in a similar case, in which the lights were extinguished at the end of Yom Kippur. He instructed the Hazan to recite the Tefila of Neilah aloud and let the people fulfil their obligation by listening.
It is generally prohibited to instruct a non-Jew to turn on the lights on Shabbat, even for the purpose of accomplishing the Misva of Tefila and Torah study.