Hello,
I think it is not a simple question. Here is what public health laws in some places say about spitting in public spaces which includes dust bin/garbage cans:
The environmental public health act of 1987 of Singapore states that you cannot spit any substance or expel mucus from the nose upon or onto any street or any public place, except in a dustbin or other receptacle provided for the deposit of refuse and rubbish;
Per § 130.07 spitting on public property it is unlawful for any person to spit or expectorate any secretion, saliva, or other substance in any place open to the public, upon any street, alleyway, walkway, gully, telephone booth, park or other public way, or in any parking lot to which the public has access, in or upon any premises, public property or vacant lot, or in any water or waterway, upon levees or tanks adjacent thereto.
In Massachusetts, general law, section 14. Whoever expectorates or spits in public locations [...] Shall be punished by a fine of not more than twenty dollars.
In Illinois code of ordinances, sec. 6.106. Spitting: it shall be unlawful to spit or expectorate on any public sidewalk or other public place or on the floor or walls of any store, theater, hall, public vehicle or other place frequented by the public or to which the public is invited. Any person violating any provision of this section shall be subject to enforcement as defined in chapter 1, article iv of this code. (ord. O-18-024, 7-19-2018
Lastly, spit is a diverse source of variety of bacteria. It might get people sick. In this case, in California, under the penal code section 347 (pc), it is illegal to willfully add poison or other harmful substances to a food, drink, or medical product (contaminated spit may disperse as dust particles) that could injure to another person. This crime is considered a felony, punishable by up to five years in prison, but if the victim suffered from great bodily injury, an additional three years in state prison could be added to the sentence. If the person doesn’t get sick from the spit in the food, the defendant could argue no harmful substance was in the food.