In the Vinaya -- see the section "Three: The 16 Dealing with Teaching Dhamma" on page 554 of The Buddhist Monastic Code, Volumes I:
SN 6:2 records that the Buddha himself had the highest respect for the Dhamma
he had discovered; that, as others might live under the guidance of a teacher,
honoring and revering him, the Buddha lived under, honored, and revered the
Dhamma. He enjoined his followers to show the same respect for the Dhamma not
only when listening to it but also when teaching it, by refusing to teach it to a
person who shows disrespect.
The following set of rules deals with situations in which a listener, in terms of
the etiquette at that time, would be regarded as showing disrespect for a teacher or
his teaching. As the Vinaya-mukha notes, a few of these cases—such as those
concerning footwear—are not considered disrespectful under certain
circumstances at present, although here the exceptions given for listeners who are
ill might be stretched to cover any situation where the listener would feel
inconvenienced or awkward if asked to comply with the etiquette of the Buddha’s
time. On the other hand, there are many ways of showing disrespect at present that
are not covered by these rules, and an argument could be made, reasoning from the
Great Standards, that a bhikkhu should not teach Dhamma to a person who showed
disrespect in any way.
And Teaching Dhamma:
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."
Ibid. starts with,
The bhikkhu's life should be wholly preparing him to gain insight into Dhamma. Only then will he have the wisdom to communicate anything of real value to others when the time is appropriate and the audience properly receptive. (A monk will usually wait for an invitation to speak on Dhamma, so there is no question about him proselytizing.) Teaching Dhamma, however, is not easy. If it is badly done, it can cause more misunderstanding than understanding.
The fourth Confession Rule came to be set down when the group-of-six monks taught Dhamma to lay people by rote, which caused the lay followers to feel disrespect for the monks:
"If a bhikkhu teaches Dhamma to an unordained person (one who is not a bhikkhu), repeating it together word by word, it is [an offence of Confession.]" (Paac. 4; Nv p.14)
"To rehearse the Dhamma word by word... was the method to teach others to memorize when there were no books. This method was formerly used in (Thai) temples and popularly known by the name 'studying books in the evening.' The aim of prohibiting pronouncing (Scripture) together is clearly shown in the original story of this training-rule which was to prevent the pupils from looking down on the teacher." (Paat. 1969 Ed. p.159)