Shu'ba reported: I asked Qatada about spitting, in the mosque. He said: I heard Anas b. Malik say: I heard the Messenger of Allah ﷺ say: Spitting in the mosque is a sin, and its expiation is that it should be buried.
The Prophet ﷺ also taught us that if we do commit any sins while inside the mosque, then we must make sure to repent for them and seek forgiveness from Allah SWT so that He may forgive us for our wrongdoings. We must also take responsibility for our actions by burying whatever dirt or filth we have created so as not to disturb anyone else who may come after us into the mosque.
This hadith serves as an important reminder for all Muslims about how they should conduct themselves when they enter a place of worship such as a mosque; with respect, humility, and mindfulness of their actions at all times so as not to offend Allah SWT or anyone else present there with them at the time of prayer or otherwise.