Sayyiduna Abu Sa'id al-Khudri (may Allah be pleased with him) said: When the Prophet (peace and blessings be upon him) had first come (to Madinah), whenever one of us was near death, we would inform him (peace and blessings be upon him). He (peace and blessings be upon him) would come and seek forgiveness for him. When he died, he (peace and blessings be upon him) and his companions would leave; sometimes he (peace and blessings be upon him) would sit until he was buried, and sometimes this staying of his (peace and blessings be upon him) became long. When we feared the hardship of this for him (peace and blessings be upon him), some of the people said to others: Why do we not inform him (peace and blessings be upon him) only when a person has died? Then when he died, we would inform him (peace and blessings be upon him), and there would be no hardship for him (peace and blessings be upon him) in it, nor would he (peace and blessings be upon him) have to stay long. So we informed him (peace and blessings be upon him) after the deceased had died. He (peace and blessings be upon him) would come and pray the funeral prayer; sometimes he (peace and blessings be upon him) would leave, and sometimes he would stay until the deceased was buried. We continued doing so for a while. Then we said: If we do not trouble him (peace and blessings be upon him), and instead carry the funeral to him (peace and blessings be upon him) so that he (peace and blessings be upon him) prays over it near his house, that will be easier for him (peace and blessings be upon him). So we did that, and the matter has remained so to this day.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الجنائز / 7181