Hats, particularly ones with brims or a peak, seem to disturb a dog's ability to recognise a person's features and they can become protective or defensive. Posties and police seemed to get bitten more than most, though posties haven't worn hats for a long time now. Unsurprisingly it's something people wouldn't think about when socialising a puppy.
We've seen several behavioural traits in our adopted dog which show he wasn't socialised as a pup. He's a nightmare when someone arrives at the door. Whilst we accept that he barks as a warning, we still haven't been able to teach him that when we allow someone in, it's because they aren't a threat to us.
He ran away the first time he saw me wearing a pair of Christmas antlers .....