Sunan Abi Dawud Book 2, Hadith 86
The Messenger of Allah(ﷺ) said: Spitting phlegm in the mosque... The narrator then transmitted the rest of the tradition to the same effect.
The Messenger of Allah (ﷺ) said: Spitting in the mosque is a sin and it is expiated by burying the spittle.
The Messenger of Allah(ﷺ) said: if anyone enters the mosque, and spits in it, or ejects phlegm, he should remove some earth and bury it there. If he does not do so, then he should spit in his clothes and not come out with it.