Whenever the Messenger of Allah ﷺ prayed over a funeral, he would say, "O Allah, forgive our living and our dead, those present among us and those absent, our young and our old, our males and our females. O Allah, whomever among us You keep alive, let him live upon Islam, and whomever among us You take in death, take him upon faith. O Allah, do not deprive us of his reward and do not lead us astray after him."
حدثنا سويد بن سعيد حدثنا علي بن مسهر عن محمد بن إسحق عن محمد بن إبراهيم عن أبي سلمة
كان رسول الله ﷺ إذا صلى على جنازة يقول اللهم اغفر لحينا وميتنا وشاهدنا وغائبنا وصغيرنا وكبيرنا وذكرنا وأنثانا اللهم من أحييته منا فأحيه على الإسلام ومن توفيته منا فتوفه على الإيمان اللهم لا تحرمنا أجره ولا تضلنا بعده
[Hasan] Bayhaqi reported it, 4/41, from the hadith of Ibn Ishaq through this route. It also has another route in Abu Dawud, no. 3201, and elsewhere, and Ibn Hibban and Hakim graded it sahih, as did Dhahabi. Yahya stated explicitly that he heard it directly, and it has many corroborating narrations.