A child should be washed and the funeral prayer offered for him according to all the scholars. Ibn Qudaamah (may Allaah have mercy on him) said that there was no dispute concerning this matter. Ibn al-Mundhir narrated that there was consensus among the scholars that a child should be prayed for. See al-Mughni, 3/458.
When the prayer is offered for a child, there should be no prayer for forgiveness, and it should not be said in the prayer “Allaahumma aghfir lahu (O Allaah forgive him),” because no sins were recorded for him. Rather prayers should be said for forgiveness and mercy for his parents. That is because of the report narrated by Abu Dawood (3180) and al-Tirmidhi (1031) from al-Mugheerah ibn Shu’bah, that the Prophet (peace and blessings of Allaah be upon him) said: “The funeral prayer should be offered for him and prayers should be said for forgiveness and mercy for his parents.” Classed as saheeh by al-Albaani in Ahkaam al-Janaa’iz, p. 73. See also question no. 13985.
And Allaah knows best. May Allaah bless our Prophet Muhammad and all his family and companions.