Abu Salama b. ‘Abd ar-Rahman told how, when Sa'd b. Abu Waqqas died, ‘A’isha said, “Take him into the mosque so that I may pray over him.” When objection was made to this she said, “I swear by God that God’s messenger prayed in the mosque over Suhail and his brother, the sons of Baida’. ”
Ibn ‘Abbas said that God's messenger came upon a grave where an interment had taken place at night and asked when this person had been buried. On being told that he had been buried the previous night, he asked why they had not informed him. They told him that they had conducted the burial in the darkness of night and had not liked to waken him, whereupon he stood up, and when they formed a row behind him he prayed over the dead.
God’s messenger prayed at a funeral and I have retained in my memory some of his supplication. He was saying, “O God, forgive him, show him mercy, grant him security, pardon him, grant him a noble provision and a spacious lodging, wash him with water, snow and ice, purify him from sins as Thou hast purified the white garment from filth, give him a better abode in place of his present one, a better family in place of his present one, and a better spouse in place of his present one, cause him to enter paradise and preserve him from the trial in the grave and the punishment in hell.” A version has “And guard him from the trial in the grave and the punishment in hell.” He added that the result was that he wished he had been that dead man.