The western idea of "take head covering off" always confused me as a kid.
When going into a Hindu temple, it was drilled into me that wearing a head covering was out of respect.
How about a ball cap in a fine restaurant? Or a Borsalino fedora, if you'd wear one at all, same question.... why not?
I went to Catholic schools. Men and boys don't wear hats in church; well, priests sometimes do. When I was young women wore hats in church--some priests would not give little girls communion unless they had some kind of hat on. At school Masses nuns would use a bobby pin to fix a Kleenex or something to the hair of hatless girls to approximate a head covering. The female side of the convention is long gone, but men don't wear hats in church.
Of course, in the Jewish and other faiths, the men were some type of headgear during services. It's interesting that both practices, hatted or hatless, are signs of respect, isn't it?
Easter hats for women are still a thing at several Catholic churches I've been to.
Part of this also is a cultural thing. A lot of Catholic churches have skewed a lot more Latin and caribbean here in NY than they were previously (Irish and Italians). I don't think the ladies wearing hats in church thing was ever a big thing in either of those cultures, though I might be off.