He greeted the Prophet ﷺ with the salam while he was praying, and the Prophet returned his greeting.
أنه سلم على النبي ﷺ وهو يصلي، فرد عليه.
No references are available.
Nasai (1188) reported it from Muhammad bin Bashshar, who said, Wahb, meaning Ibn Jareer, told us, he said, my father told us, from Qays bin Saad, from Ataa, from Muhammad bin Ali, from Ammar bin Yasir, and he related the same. Its isnad is sahih. Ataa is Ibn Abu Rabah, and Muhammad bin Ali is Ibn Hanafiya.Imam Ahmad (18718) reported it from Affan, Hammad bin Salama told us, Abu Zubayr told us, from Muhammad bin Ali bin Hanafiya, from Ammar, and he related the same.There is disagreement regarding this response to a greeting. Nasai treated it as being by gesture, since he related the hadith under the chapter heading, "Returning a greeting by gesture during prayer." Hazimi, however, placed it under the chapter of what speech has been abrogated during prayer, and he traced a report from Sufyan bin Uyayna in which he said, "This, in my view, is abrogated." Itibar (p. 71).I say, the matter could go either way. If it was by speech, then it took place before the abrogation, and if it was by gesture, then it took place after the abrogation. However, Ibn Qani related in Mujam Sahaba (2/249) from Muhammad bin Muhammad bin Hayan Tammar in Basra, Abu Salama told us, he said, I heard Jareer bin Hazim say, I heard Qays, meaning Ibn Saad, narrating from Ataa, from Muhammad bin Ali, that Ammar bin Yasir passed by the Prophet ﷺ while he was praying, so he greeted him, and he gestured back to him. If this report is sound, it confirms the second possibility.What can be drawn from the hadiths on this subject is that there is no harm in returning a greeting during prayer by gesture, and it is also permissible to return it after finishing the prayer, just as the Prophet ﷺ returned the greeting to Ibn Masud after he had finished his prayer.Abu Hanifa said, one should neither return the greeting nor gesture.