“A person should pray only in a house with windows, as it is written (Daniel 6:11), ‘and his windows opened from his loft towards Yerushalayim'” (Berakhot 34b). While there is an opinion that this applies only to prayers in a private house, most Rishonim and the Shulchan Arukh (OC 90:4) learn from this that a shul should have windows, preferably in the direction of Yerushalayim.
The Beit Yosef brings a number of explanations for this law. Rashi’s explanation is that the window exposes the sky, reminding us of our subordination to Heaven.
The Rambam writes that we should in effect gaze towards Yerushalayim. One explanation in Rabbenu Yonah is that one’s intention is better when there is light.
An interesting variation on this theme stems from a story told about Rav Yehuda Amital. The story goes that when the Beit Midrash for his yeshiva was first built, the architect wanted to make it without windows with a view of the surrounding landscape. The rationale was that this design made the building fit in better with the environment. Rav Amital’s response was typical of his perpetual emphasis on the human element in serving G^d: It is the students, rather than the building, who must fit in with the environment! In other words, the place of Torah study is not meant to be a place where students are completely isolated from the outside world; it is a refuge but one that retains a constant awareness of the life of the nation and the world.
A similar insight can be applied to a place of prayer. While prayer is a private confrontation between the individual and G^d, the subject of our prayers include earthly matters such as health and livelihood. Having windows reminds us that our prayers are not meant to be isolated from the world outside. (Of course it is critical that the view should not be of anything distracting or immodest.)
The Beit Yosef gives an additional source for the need for a window, the Zohar (Pikudei II:251a). The Zohar gives a remarkable explanation of a verse from Shir HaShirim: “Behold, one stands behind our wall, gazing through the windows, peeping through the lattice” (Shir HaShirim 2:9).
These two kinds of vision represent two different levels of Divine Providence. “Peeping through the lattice” is a narrow level of supervision in which not all is seen; “gazing through the window” is a broader level which reveals all of a person’s acts.
The Yedid Nefesh commentary of Rabbi Yechiel Bar Lev explains that the narrow supervision is focused on our acts, while the broader view encompasses also our prayers. It is significant that “gazing through the window” precedes “peeping through the lattice”; this means that G^d judges us on our actions, but He does so in the broader context of our desires and our turning towards Hashem. This leads to a lenient judgment; acts which narrowly perceived would seem improper can be justified or excused when seen in context.
According to this approach, the windows in a shul correspond to the “windows” of Divine supervision. We put windows in the place of prayer to symbolize Hashem’s window on our prayers. The opening reminds us of the opening to heaven through which G^d perceives our true inner desires and our reliance on Him. When we remember that He will judge our acts in the context of the content of our prayers, our prayers should be deeper and more sincere.