Here is an example of what I'm referring to.
Relevant Question: When did this style (wearing hats in public (top hats etc)) come into style, and what were the reasons that lead to it increasing in popularity throughout the west?
Head coverings are worn throughout history for numerous different reasons; sun protection, keeping the hair clean from dust/dirt/smoke, finishing off one's appearance, covering up a bad hair day or balding, etc. It's very difficult to come up with a start date for wearing hats in general since it has been done for so long and in such variety. Sometimes large, sometimes small, these all served different purposes and their fashion came from many sources. Men's hat styles from around 1900 were a gradual shift from the cocked hat styles of the 17th and 18th centuries. Even those had gradual sources further back as well. That time is just easy to point to as similar, since most men were wearing variations on the same cocked hat style when going out with a universal nature not unlike that photograph you linked.
As for why they were worn, or how they were viewed it's equally complex. Wearing a hat when you go out was considered part of finishing off the outfit. Much like you can't enter most establishments without shirt or shoes today, it was just part of looking put together. It wasn't even a conscious decision to put on a hat every time you went out, worrying that you'd be made fun of, it just felt weird with out like forgetting your left sock or your cellphone today. Hats were practical as well. In a time before sunscreen was as easy as it is today (and when tanning was not fashionable) a hat provides the easiest way to replace that. Rain, dust, dirt, ash, smoke, and all of the other things that can dirty and cause the hair to smell in both industrial cities and countryside are easily prevented by way of a hat as well.
The disappearance of men's hats coincide with a general change in fashion during the later 20th century. The wearing of suits for everyday use also fades out starting in the 1970s. Women's hats hold on for just a slight bit longer, but they too fade by the end of the century. Fashion simply becomes more casual. Hair is left down and "un-done". People wear previously casual clothing kept to circumstances like sportswear or even pajamas in everyday public situations. Hats just aren't part of casual wear (though baseball caps can be seen as part of sports attire that's regular worn now), so they fade out just as suits, ties, dresses, and other pieces have out of daily life.