The Prophet ﷺ said, "Whoever spits in the mosque should dig a hole and bury it deep, otherwise let him spit into his garment."
حدثنا حماد بن خالد عن أبي مودود عن عبد الرحمن بن أبي حدرد
أن النبي ﷺ قال من بزق في المسجد فليحفر فليبعد وإلا بزق في ثوبه
Its isnad is sahih. It was mentioned previously at 10052. Abu Mawdud is Bahr bin Musa, whom Ibn Hibban and Ajli and others deemed trustworthy.