Mishkat al-Masabih 466
وَعَنْ نَافِعٍ قَالَ: انْطَلَقْتُ مَعَ ابْنِ عُمَرَ فِي حَاجَة إِلَى ابْن عَبَّاس فَقَضَى ابْنُ عُمَرَ حَاجَتَهُ وَكَانَ مِنْ حَدِيثِهِ يَوْمَئِذٍ أَنْ قَالَ مَرَّ رَجُلٌ فِي سِكَّةٍ مِنَ السِّكَكِ فَلَقِيَ رَسُولَ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ وَقَدْ خَرَجَ مِنْ غَائِطٍ أَوْ بَوْلٍ فَسَلَّمَ عَلَيْهِ فَلَمْ يَرُدَّ عَلَيْهِ حَتَّى كَادَ الرَّجُلُ أَنْ يَتَوَارَى فِي السِّكَّةِ ضَرَبَ رَسُولُ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ بِيَدَيْهِ عَلَى الْحَائِطِ وَمَسَحَ بِهِمَا وَجْهَهُ ثُمَّ ضَرَبَ ضَرْبَةً أُخْرَى فَمَسَحَ ذِرَاعَيْهِ ثُمَّ رَدَّ عَلَى الرَّجُلِ السَّلَامَ وَقَالَ: «إِنَّهُ لَمْ يَمْنَعْنِي أَنْ أَرُدَّ عَلَيْكَ السَّلَامَ إِلَّا أَنِّي لَمْ أَكُنْ على طهر» . رَوَاهُ أَبُو دَاوُد
From Nafiʿ, who said: I went with Ibn ʿUmar on some business to Ibn ʿAbbas. Ibn ʿUmar finished his business, and among what he narrated that day was that he said: A man passed in one of the alleys and met the Messenger of Allah ﷺ, who had come out from relieving himself or urinating. He greeted him, but he did not return his greeting until, when the man was about to disappear in the alley, the Messenger of Allah ﷺ struck the wall with his hands and wiped his face with them, then struck another strike and wiped his forearms. Then he returned the man's greeting and said: "Nothing prevented me from returning your greeting except that I was not in a state of purity." Reported by Abu Dawud.