On the Pearl lasyt summer our family was turned away the first night because our dtr and SIL were in jeans. Their luggage had not arrived and it has always been customary to relax the dress code the first night.
They were very polite and directed us to the other dining room. (NCL has the best of both worlds in that the two main dining rooms are divided by dressy and decent jeans attire). They nicely escorted us to the other dining room and saw that we did not have to wait in line again.
I actually was pleased that they made a rule and stuck to it.
I've been on several ships and seen people turned away at supper for shorts. Even a Carnival ship! However, I've never seen them ask men to remove their caps. My grandmother would roll over in her grave if anyone had come to dinner with a hat on.