The following rules are part of the Sekhiya rules of the Patimokkha. The Patimokkha are rules for (Theravada) monks and nuns.
I will not teach Dhamma to a person wearing headgear who is not ill: a training to be observed.
I will not teach Dhamma to a person whose head is covered (with a robe or scarf) and who is not ill: a training to be observed.
The explanation for these come in "The Bhikkhus' Rules: A Guide for Laypeople" by Bhikkhu Ariyesako:
Sixteen of the Sekhiya Training rules set down how and to whom a
bhikkhu should teach Dhamma. These rules are also concerned with the
etiquette of showing respect, respect not only for the bhikkhu but
more importantly for the Dhamma that he is teaching. (The Great
Standards would imply here that modern ways of showing respect and
disrespect would be similarly covered by these rules.) These rules
prohibit a bhikkhu from teaching anyone he considers to be showing
disrespect to the Dhamma. Here is a summary of these Sekhiya
Trainings:
"I will not teach Dhamma to someone who is not sick but who:
— has an umbrella; a wooden stick (club); weapon in their hand.
— is wearing (wooden-soled) sandals/shoes; is in a vehicle; is on a
bed (or couch); is sitting clasping the knees; has a head wrapping
(turban); whose head is covered; who is sitting on a seat while I am
sitting on the ground; who is sitting on a high seat while I am
sitting on a low seat; who is sitting while I am standing; who is
walking in front of me while I am walking behind; who is walking on a
pathway while I am walking beside the pathway." (Sekhiya 57-72; See
BMC pp.505-508)
How these rules are observed may diverge in different communities.
Some will strictly follow the above while others will be more flexible
according to modern conditions. As Venerable Brahmava"ngso remarks:
"...These Sekhiyas ensure that one teaches Dhamma only to an audience
which shows respect. One may not expound from a soapbox in the
marketplace... to the indifference of passers by. However it is common
these days in the West for a seated audience, wearing their shoes and
maybe even a hat, to respectfully listen to a speaker standing at a
lectern... and as the audience is considered to be behaving
respectfully according to the prevailing norms there seems no reason
why a monk may not teach Dhamma in such a situation." (AB)