Hats were commonplace before 3000 BC. One of the earliest known hats was worn by a Bronze Age man called Otzi - was his name written inside his hat?
Otzi was found frozen inside a mountain between Italy and Austria, where he had lain since 3250 BC. Presumably his hat had long since ceased to keep his head warm, but it was a bearskin cap, so he must have been a pretty tough guy when he was alive.
There are so many reasons for wearing hats that I find myself scratching my head as to where to begin, or at least I think that's why I'm scratching my head. There are hats for protection against the weather, ceremonial hats, hard hats to prevent injury, military hats to denote rank or regiment, hats as fashion accessories, and modern police helmets which are much more difficult to knock off with a snowball than the old-fashioned ones were. (So I'm told, and I have an alibi if necessary.)
Some hats are associated with certain people. Sherlock Holmes sported a 'deerstalker', Davy Crockett, "King of the Wild Frontier", wore a raccoon cap (dead) on his head. Napoleon, Tommy Cooper, Tam o' Shanter, Lady Gaga, they all had, or have, their own signature styles in millinery. The term 'milliner' comes from the Italian city of Milan, but other brands are available. Not sure if you can still buy a Dunce's cap, though. My old one must be worth a few euros by now.
All guests in the Royal Enclosure at Ascot must wear a hat, and they wouldn't let me in without one. The horse I backed came in last, anyway. Royal personages sometimes have to don crowns, although the humorous writers Sellar and Yeatman warned that "Uneasy lies the head that wears a Throne."
It must be comforting to live in the city of Medicine Hat in Canada, which is the sunniest place in the country and also presumably the healthiest, as long as you remember to keep some medicine under your hat. I do worry slightly about the inhabitants of Saltcoats in Scotland -- are they always thirsty? (Most Scotsmen are.) Stetson in America bears the same name as the cowboy hat manufacturer, although they also made hats for the Canadian 'Mounties'. If you want to get ahead, or a horse, get a hat.
Women still wear hats these days but men less frequently do. I must admit that I find most women's hats inscrutable (and most women too). Nowadays the only practical use of a top hat, for example, would be for a magician to produce a rabbit out of it, something probably forbidden by animal welfare regulations. Magicians, like rabbits, are a dying breed, and if you are someone struggling to keep old traditions alive, well, what can I say? I take my hat off to you.