It depends on the material. Too much water can damage a straw or paper hat. However, it is safe to sweep a wet microfiber cloth over its surface. Any detailing like ribbons and beadings should be removed before cleaning, if possible, and hand washed.
Other sun hats made of materials like cotton, felt or polyester can be easily washed. Just place it in a leak-proof container and add a teaspoon of detergent to it. Fill it halfway with warm water and then close the lid and shake. The detergent will attack, and release grime and dirt into the water to give you a clean sun hat!