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.
قَالَ رَسُولُ اللَّهِ ﷺ مَنْ دَخَلَ هَذَا الْمَسْجِدَ فَبَزَقَ فِيهِ أَوْ تَنَخَّمَ فَلْيَحْفِرْ فَلْيَدْفِنْهُ فَإِنْ لَمْ يَفْعَلْ فَلْيَبْزُقْ فِي ثَوْبِهِ ثُمَّ لْيَخْرُجْ بِهِ