Someone in shul told me last Shabbat that I should not wear shorts to shul. When I told him I learned it is permitted, he said that Shabbat is different. Why should Shabbat change the halacha? Answer:
Halachot like these involving clothes tend to be subjective. However, one needs to start with the halachic philosophy and standard situations. We wrote (Eikev 5771) about wearing shorts, with a focus on a chazan, and we refer you there for additional sources.
When one davens, he stands before Hashem and should be dressed respectably (Shabbat 10a; Shulchan Aruch, Orach Chayim 91). The Shulchan Aruch (ibid. 4) says that this includes covering one’s legs, when this is how people dress before important people. The Mishna Berura (91:12) adds that one should wear a hat, explaining that this is the way people dress publicly. (In some circles, this is still true; in others, it does not apply at all).
Even in surroundings where one should cover his legs, there are limits to the severity of the matter. One’s tefilla is invalid after the fact only if his private parts are uncovered (Shulchan Aruch, Orach Chayim 91:1) or there is no separation between his heart and private parts (Biur Halacha ad loc.). There is some question as to whether it is better to daven or to skip davening if he is not able to cover his chest (ibid.). Regarding other "improper attire," including one who has only shorts, he may daven. However, the Shulchan Aruch (ibid. 5) writes that when it is possible, one must be properly dressed.
Rav Ovadya Yosef (Yechaveh Da’at IV:8 – see also the dissenters he cites) says that in places (e.g., kibbutzim) and for people (children during the summer) where shorts are commonplace, it is permitted to daven in shorts (not as a chazan). We accept that approach, which leads to the challenge of determining whether short pants are commonplace enough in a give venue.
Does Shabbat change anything? Actually, shorts on Shabbat, not just at the time of davening deserves a similar discussion to the above, as one is supposed to wear nice clothing on Shabbat (Shulchan Aruch, OC 262:2). This is not a matter of oneg (enjoyment) but of kavod (honoring Shabbat), and this applies even when one is by himself (Mishna Berura 262:6) or prefers more casual clothes. Here, too, societal factors are crucial in determining what types of clothes are necessary, praiseworthy, and appropriate. (The Biur Halacha to 262:3 discusses whether wearing white clothes is showing off. In some circles, the same question could be raised about wearing a black hat, while in others a hat or even a shtreimel are expected). Factors such as age, weather, venue (vacation resort, camp) may also play a role.
Logic dictates that since we are taking a practical, subjective approach, there is every reason to combine factors. On average, people dress more formally at tefilla on Shabbat than they do either at tefilla during the week or on Shabbat outside of shul. The same is true regarding standing before important people, the model for attire for davening. One is likely to dress more formally at a formal setting with an important person than at a casual setting with him. We also find the honor of Shabbat elevating the prominence of other halachic matters. For example, a Shabbat meal warrants Sheva Berachot even without panim chadashot (Shulchan Aruch, Even Haezer 62:8); even minor eating (ara’i) is forbidden on Shabbat before taking ma’aser (Rambam, Ma’aser 3:4).
In summation, if it is rare for people to come to shul in your community with shorts on Shabbat, we would certainly agree with the content of the person who spoke to you (hopefully, in an appropriate way, which is not always easily done). If it is not uncommon, one needs to know where to draw the line, which is best done by local rabbis with a finger on the pulse of the community. In general, though, it is appropriate for the norm to be to wear long pants.