Looks like you would need compound image options: One piece of clothing (the hat) that is created from 2 (or even more..) different png-images with each having a different z-value: Part of it in front of the head and some of it behind the head (and hair). That’s a lot of work for one piece of clothing but it would work with some other similar options too.
I’d say the quick-fix is to put the hair and the hat into the same option. That obviously has some disadvantages as you can’t choose the hair freely.
I would vote for doing both: Give us a few of these problematic hats in the hair-options and think about creating the compound-image-options in the long run. Are there other pieces of clothing that need to be in front and behind the character at the same time?