´Abu Jubair bin Hayyah narrated that he heard Mughirah bin Shu’bah say:` “I heard the Messenger of Allah (ﷺ) say: ‘The (funeral) prayer should be offered for a child.’”
Hadith Referenceسنن ابن ماجه / كتاب الجنائز / 1507
Hadith Gradingالألبانی:صحيح | زبیر علی زئی:إسناده صحيح
➊ In the narration of Sunan Abu Dawood, this hadith is mentioned in these words: The funeral prayer (salat al-janazah) should be performed for the stillborn child, and forgiveness and mercy should be supplicated for his parents. (Sunan Abi Dawood, al-Jana'iz, Chapter: Walking in front of the bier, Hadith: 3180)
➋ The funeral prayer (salat al-janazah) for a child born dead should be performed in the case when he was born after the completion of four months of pregnancy or thereafter. Because at that time, the soul (ruh) is breathed into the fetus. Therefore, only the one born after this can be considered a deceased (mayyit).
Source: Commentary on Sunan Ibn Mājah by Mawlānā ‘Atā’ullāh Sājid, Page: 1507