In short, just answering this question (which as stated in the other comment is not the issue), yes that person has t done anything wrong. There is no offence for wearing hats in banks.
But banks aren't mandated to admit you either. Just because it's legal, doesn't mean a private establishment has to let you in. When it comes to denying entry, banks are relatively tame. Some establishments go beyond that, by denying entry unless you wear formal clothing, or presenting proof of identity.