I think it's one of those areas where the RF hang on to the more formal practices of earlier ages. My grandmother (born mid 1890s) would not have set foot in a church without a hat, mind you it was a rare day she went beyond the garden gate without one. Another relative, same sort of age as the late Queen, never wore a hat (and was a keen supporter of "messy church" for kids in her quite sedate parish)
It might also be about visibility. We expect royal women to be wearing hats at certain occasions including church, it makes them stand out (and probably easier for the photographers to spot)