I frequently wondered about this myself. Not so much about the custom for
"hats" per se, which is based upon halacha; A man should wear a hat for
prayer, Birchas Hamazon (Grace after Meals) and some other occasions. But
why BLACK? Indeed why did Jewish clothing especially in Eastern Europe
evolve into almost entirely BLACK?
What makes it most puzzling is the fact that in Talmudic times, Black
clothing were clearly associated with mourning and even sinfulness and shame.
Elsewhere it says that a Talmud Chochom (Torah scholar) should dress in
white (I don't recall where).
So why black?
In an effort to find an answer I checked the Encyclopedia Judaica (under
"Dress"). It says that "In medieval Spain, Jews were obliged at times to
wear a full length black gown with a cape and pointed hood". It also lists
numerous periods and nations that required specific clothing for Jews. (
Interestingly the kapotoh or kaftan, commonly worn still today by many
Chasidim, originated in the Turkish Empire.)
Aside from the reference about medieval Spain, the black color is not
mentioned as a requirement, although black hats and kaftans were the
distinctive feature of Jewish costume, at least by the early 18th century.
So I'm afraid my information is still incomplete.