The GA is simply doing his/her job to ensure IDs are matched. That said, he/she is also reminding travelers how to use said hat in a polite fashion. Wearing hats indoors is rude. The army taught this to me when I was a reservist.
Surprised I have to link this:
https://www.thespruce.com/etiquette-...ndoors-1216685