You could have an activity set up outside (water play, for eg) and then persist in putting his hat back on if he takes it off. If he's distracted he might be less interested in removing the hat and a firm "We have to wear hats outside" is enough.

Just a thought - do you and DH wear hats outside as well? Because if he's seeing DH walk around outside without a hat then it's going to be harder to get him to leave his own on.