My suspicion, based on where this occurred, is that it's to match your ID.
Different jurisdictions have different laws on what can and cannot be worn in IDs, but religious headwear is often allowed.
Also, there's a huge difference between being asked to remove your hat and being asked to remove your turban or yarmulke.
Though I suspect even then, it would be more the removal of a hijab that would cause problems.