Hats in Exit the Gungeon do not do anything for your character. They do not improve your gameplay, your fire rate, the amount of damage you do, or anything else that could help you continue further in the game. Instead, they’re cosmetic items that you can place on the top of your chosen character’s head and watch them run around with it on while you fight.
You do not have immediate access to these hats, though. You receive your first three before and after completing your training with Manuel. He provides you with one for listening to him, for disobeying him, and then completing your training. There are 34 hats you can purchase, though. To grab them, you need to unlock Hattori. You need to save them by buying a Rat key and continuing through the game as one of the four Gungeoneers you start the game with. They will unlock Hattori during their run, and give you access to the appearance options.
The Hattori will provide you with hats if you have the hegemony credits to purchase them. You can earn hegemony by defeating bosses in the game. You want to make sure if you purchase these you want to do it. The same currency you use to buy those appearance items are the same ones you use to get additional items and weapons for your Exit the Gungeon runs.
You need to figure out if you want to buy all of the items and weapons in the game first or start purchasing appearance hats for your characters. It varies on what items and weapons you already have available and how many hegemony credits you have been able to acquire reliably.