First seen in flash forward, the reason Marshall is wearing this hat isn’t revealed until Episode 221, SOMETHING BORROWED. On his wedding day, Marshall is first given bleached tips in his hair before he runs a razor through it, shaving off a strip of hair. Out comes the Fedora.
Reiko Kurumada (Costume Designer): “It was a very last-minute decision for him to throw on a Fedora, and we were shooting that at the park across the street from Fox, early in the morning. Someone asked, ‘Do we have a fedora?’ So we ran back to Fox Wardrobe Department and grabbed it at the last second.”