The Prophet ﷺ said to one of his daughters when her son was dying, "To Allah belongs what He takes and to Him belongs what He gives, and everything with Him has an appointed term. So let her be patient and seek the reward."
قال النبي ﷺ إحدى بناته عند وفاة ابنها: إن لله ما أخذ، وله ما أعطى، وكل شيء عنده بأجل مسمى، فلتصبر ولتحتسب.
Bukhari related it in the Book of Funerals (1284), and Muslim in the Book of Funerals (923), both through the route of Asim bin Sulayman Ahwal, from Abu Uthman Nahdi, from Usama bin Zayd, who narrated it.