Originally hats were worn as a sign of formality and Mishna Brurah brings in a number of places that one is obligated to wear a hat for davening and benching as one would when standing before a king. Also, Mishna Brurah writes that one should wear longer, and presumably more formal, clothing on Shabbos than is worn during the week. However this reason is not completely relevant today, as modern Western society does not view a hat as formal attire.
There is also an issue in Kabbala that would be more relevant to Chassidim.
Additionally, wearing a black hat over the years has become a form of a uniform identifying its wearer as part of the yeshiva community. When one walks down the street is a hat and jacket he proclaims himself different from the rest of Western society and a representative of a specific segment of the population, with all the responsibility that this involves and entails. Understandably, some people find this conflicts with their profession and occupation, and dress in a way that is less obtrusive at work. Alternatively, some may feel that their personal behavior does not meet up to the lofty standards that this manner of dress is intended to imply. However on Shabbos there is no conflict with one's livelihood and one is free of mundane concerns to focus on the spiritual, so people feel free to express how they would deep inside like to associate themselves.
So, today there may not be any halachic imperative to wear a hat, there are still many good reasons to do so. And in this perspective, I believe it is possible to understand why many people may choose to wear them only on Shabbos.