Q. Does one perform a mitzvah simply by sitting in a shul or beis medrash, even when not davening or learning Torah? What would that mitzvah be?
Shulchan Aruch (O.H. 151: 1) rules in regards to entering a shul or a beis hamedresh to call someone, that he should first sit some time, since staying in them is a mitzva, as it is written; “Ashrei yoshvei beisecha.” We indeed recite thrice a day the Psalm (145) of Ashrei yoshvei beisecha, often translated as praiseworthy are the dwellers of your house. We also thank Hashem after finishing learning and after ending a volume of Talmud; “Samta chelkeinu miyoshvei beis hamedresh” for having given us the opportunity of being from the ones that stay or reside in a beis hamedresh.
A House of Study also offers spiritual protection from the surrounding dangers of the libertine streets.
(See Suka 52b)
On Pirkei Avos (5: 17) we mention: There are four types among those who attend the house of study:
He who goes and does not study–he has the reward of his going. It would seem that just attending is a rewarded mitzva.
Horav Shlomo Miller Shlit’a explained that the reason the one who does not study is rewarded, is due to the kavod and honor he bestows on the Torah being learned in the beis hamedresh.
Rabbi A. Bartfeld as revised by Horav Shlomo Miller Shlit’a