Yes, you can! Hats in Team Fortress 2 are obtained through the game's Item Drop System, which rewards players with random items—including coveted hats—simply for playing.