The Messenger of Allah ﷺ said, "Spitting in the mosque is a sin, and its expiation is to bury it."
حدثنا قتيبة حدثنا أبو عوانة عن قتادة
قال رسول الله ﷺ البزاق في المسجد خطيئة وكفارتها دفنها
Agreed upon by Bukhari and Muslim. Muslim narrated it in the Book of Masjids, chapter on the prohibition of spitting in the masjid, etc, hadith no. 552, from Qutayba, and Bukhari, hadith no. 415, from the hadith of Qatada with the same wording.