part of a mesh doesn't move with the rest
This is actually quite simple, you just didn't add weight on  the hat



As you can see, the hat has 0 weight, the amount of weight it has is how much influence the bone has on that part of the mesh



Here I set the weight on the hat to 1 (Max influence) so the head bone has 100% control over the hat, an easy way to add the weight to individual objects is to separate them in edit mode using "P" then select "Loose parts", I don't like to have all objects joined in one single mesh because that complicates things when doing weight painting or other stuff involving rigging

so there you go!, just set the hat weight to 1 and that's it, easy cake :)