A cap, and I'm thinking of a baseball cap, would be worn by someone who is using it hide themselves to some degree. It is representative then of nervousness or anxiety in the wearer when that is in the context of a classroom online or offline. It makes them feel protected. It is my job as a teacher to make the student feel comfortable and confident, so that the cap is no longer required. Although it may be that the cap is hiding them from someone or something else, not the teacher. I wouldn't ask a student to take it off, or do anything that made them feel uncomfortable.
If a teacher, on the other hand is wearing a cap in a lesson other than as realia or a prop, then as a student I would be concerned.