There is a hat shop at the northeast corner of Plaza Mayor. They have a huge variety of police, military and other caps. A friend was able to get the distinctive tri-corner hat of the guardia civil there. It is just to your right as you enter the plaza from calle Postas.