To grab a hat for free on level two in Mathletics, you'll first need to earn plenty of credits. Once you have enough, click on your avatar or character and select your gender, then choose the option to spend your credits.
From there, click on Accessories and pick any hat you like. You can try it on before buying it, so you can find the perfect look for your character.