Nafi' said: I went with Sayyiduna Ibn Umar (may Allah be pleased with him) to Ibn Abbas (may Allah be pleased with him) for some need. When he had fulfilled his need, he narrated this hadith: A man passed by the Messenger of Allah (peace and blessings be upon him) in one of the streets, when he (peace and blessings be upon him) had come out from relieving himself or urinating, and greeted him, but he (peace and blessings be upon him) did not return his greeting. Then, when the man was about to disappear from the street, he (peace and blessings be upon him) struck his hands on the wall and wiped his face, then struck his hands a second time 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."
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الطهارة / 1032