Sayyiduna Jabir (may Allah be pleased with him) narrates that the Prophet (peace and blessings be upon him) sent him on an errand of his. When he came back, the Messenger of Allah (peace and blessings be upon him) was praying. He greeted him (peace and blessings be upon him) with salam, and he (peace and blessings be upon him) did not reply to the greeting but gestured with his hand. Then, when he (peace and blessings be upon him) had given the salam ending the prayer, he said: "I would certainly have replied to your greeting, but I was in prayer."
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الصلاة / 3399