In line with the Qur'anQur'an 2:125 ↗وَإِذۡ جَعَلۡنَا ٱلۡبَيۡتَ مَثَابَةٗ لِّلنَّاسِ وَأَمۡنٗا وَٱتَّخِذُواْ مِن مَّقَامِ إِبۡرَٰهِـۧمَ مُصَلّٗىۖ وَعَهِدۡنَآ إِلَىٰٓ إِبۡرَٰهِـۧمَ وَإِسۡمَٰعِيلَ أَن طَهِّرَا بَيۡتِيَ لِلطَّآئِفِينَ وَٱلۡعَٰكِفِينَ وَٱلرُّكَّعِ ٱلسُّجُودِ
And We made the House a focal point for the people, and a sanctuary. Use the shrine of Abraham as a place of prayer. And We commissioned Abraham and Ishmael, “Sanctify My House for those who circle around it, and those who seclude themselves in it, and those who kneel and prostrate.”
The verse commands purifying God's House for those who worship there, matching the report's teaching that soiling the mosque is wrong and must be remedied.
In line with the Qur'anQur'an 11:114 ↗وَأَقِمِ ٱلصَّلَوٰةَ طَرَفَيِ ٱلنَّهَارِ وَزُلَفٗا مِّنَ ٱلَّيۡلِۚ إِنَّ ٱلۡحَسَنَٰتِ يُذۡهِبۡنَ ٱلسَّيِّـَٔاتِۚ ذَٰلِكَ ذِكۡرَىٰ لِلذَّٰكِرِينَ
Perform the prayer at the borders of the day, and during the approaches of the night. The good deeds take away the bad deeds. This is a reminder for those who remember.
The verse says good deeds remove bad deeds, matching the idea that burying the spittle expiates the fault; the specific act is not in the verse.