If a non-Jew turned on a light for a Jew on Shabbat – such as if a housekeeper sees her Jewish boss sitting in a dark room, and comes and turns on the light – the Jew may not then benefit from that light. Tosafot (Medieval French and German scholars) explain that the Sages forbade benefiting from the light in such a case because if one does benefit from the light, he might on another occasion ask a non-Jew to turn on the light for him, which is forbidden. An exception to this rule is where there was already light in the room where a Jew was sitting and reading, and the non-Jew turned the knob to enhance the amount of light and make it easier for the Jew to read. In such a case, the Jew may benefit from the light, since he was able to read even without the additional light, which merely made it a bit easier to read.
A number of Poskim discuss the situation where a non-Jew mistakenly turned off the light in a room where a Jew was reading, and then, upon realizing his mistake, turned it back on. This can happen if the non-Jew did not realize that the Jew was in the room, or if he wished to turn the knob to add more light, but in the process he mistakenly first turned the light off. The Eliyahu Rabba (Rav Eliyahu Shapiro, Prague, 1660-1712) ruled that the Jew may benefit from the light in such a case, despite the fact that in the end the non-Jew turned the light on for a Jew. Since the prohibition was enacted out of concern that the Jew might ask a non-Jew to turn on the light, it does not apply in this case, when the light was on already, and it was the gentile who turned it off in the first place. This is also the ruling of the Peri Megadim (Rav Yosef Teomim, 1727-1792), in Eshel Abraham (276:13).
There are, however, several exceptions to this ruling. First, it does not apply if the Jew asked the non-Jew to turn the light back on; the light is permissible for use only if the non-Jew understood on his own after turning it off that he should put it back on, without being asked by the Jew. Secondly, this Halacha does not apply if a Jew was reading in an illuminated room and then walked out, whereupon the non-Jew turned the light off. In this case, if the non-Jew then turns the light back on for the Jew, the Jew may not use the light. Since the Jew was not using the lit room at the time the non-Jew turned off the light, this leniency does not apply, and the light may not be used if the gentile then turns it back on for the Jew when he returns.
(Based on Hacham David Yosef’s recently-published work on Amira Le’akum, vol. 2)
Summary: If a Jew was reading in a lit room, and a gentile mistakenly turned the light off and then immediately turned it back on, the Jew may derive benefit from the light, as long as he was in the room when the light was turned off, and he did not ask the non-Jew to turn the light back on.