Shuayb reported,

Ibn Shihab said that the funeral prayer is performed over every infant who dies, even if born out of wedlock, because the child was born upon the natural disposition of Islam. If both parents claim Islam, or even just the father, while the mother follows another religion, the prayer is still performed over the child provided it cried aloud at birth. The prayer is not performed over one who did not cry at birth, since it is considered a stillbirth.Abu Hurairah رضي الله عنه used to relate that the Prophet ﷺ said, "There is no newborn except that it is born upon the natural disposition. Then its parents make it a Jew, a Christian, or a Magian, just as an animal gives birth to a whole and complete offspring. Do you find any mutilation in it?"Then Abu Hurairah رضي الله عنه would recite, "The natural disposition of Allah upon which He created mankind" [Rum 30:30].

Bukhari 1358

Sahih

حدثنا أبو اليمان أخبرنا

شعيب قال

ابن شهاب يصلى على كل مولود متوفى وإن كان لغية من أجل أنه ولد على فطرة الإسلام يدعي أبواه الإسلام أو أبوه خاصة وإن كانت أمه على غير الإسلام إذا استهل صارخا صلي عليه ولا يصلى على من لا يستهل من أجل أنه سقط فإن أبا هريرة رضي الله عنه كان يحدث قال النبي ﷺ ما من مولود إلا يولد على الفطرة فأبواه يهودانه أو ينصرانه أو يمجسانه كما تنتج البهيمة بهيمة جمعاء هل تحسون فيها من جدعاء ثم يقول أبو هريرة رضي الله عنه {فطرة الله التي فطر الناس عليها} الآية

البخاري 1358صحيح
Contents
Reference
Commentary
Ayat
Collection
Sahih Bukhari
Book
Funerals
Chapter
If a boy accepts Islam and dies, should the funeral prayer be prayed for him, and should Islam be offered to the boy
Numbering
Darussalam 1358
Bukhari 1358