You can get hats through the random drop system or by crafting weapons. Every 4 hours, 17 minutes, and 10 seconds you have a 3.5714% chance of receiving a hat.
You play. Lol.
OR you can be a total noob and go onto a server that auto-gives stuff. But that isnt fun!