What you must understand is that there are truly great programmers in the world, capable of churning out code to solve any problem. ANY problem. And there are managers in this world who have truly strange problems.
- Manager: "Can you build me a web site that turns users who visit it into fish?"
- Great Programmer: "Yes! Give me 2 weeks and all the Mountain Dew I can drink."
- Manager: "So let it be written, so let it be done!"
You can see the problems that can arise. Because the GPs cannot be prevented from programming something, we have to constantly supply them with problems to solve -- harmless, yet tricky problems, something that consumes enough of their bandwidth that when the manager comes around asking for fish web sites, the GP replies, "Sorry... I'm busy."
Hats are likely a manifestation of this. You can imagine the situation: a tech lead sees a manager coming down the hall, mind full of mauve databases. The tech lead listens and hears only silence from the GP... no typing! That means that the current queue of problems has been solved! The GP will take the first interesting problem that comes around! Do you see the look of terror on the tech lead's face? The TL looks around frantically and spots... a hat! And blurts out, "Hey, GP, I bet you can't put hats on all the icons of people who do various achievements, and do it in a way that doesn't interfere with their icons." And the GP replies, "I bet I can!" And the GP is lost deep in the code before the manager has a chance to say, "Good afternoon!"
So, wear your hat proudly. And be grateful that you're not a fish.
PS: To answer your question, in this case, the hats are plot devices. ;-)