This question already has an answer here:
On English Language & Usage, I noticed that even the Community user has hats.
In its case, how is the hat it is wearing selected?
Moderators have the ability to choose the Community♦ user's hats. You should be able to find your friendly local moderator in your site's chatroom!
Just a guess, but my hunch is that the Stack employees whose job is “Community Coordinator” (or the like) can actually authenticate as the Community♦ user to do something manually like this.
Either that, or a developer.