All perfect praise be to Allah the Lord of the Worlds. May His peace and blessings be upon our Prophet Mohammad and upon all his family and companions.
Mother by descent has preferential right to custody of the child who is incapable of discernment if her eligibility is ensured and nothing prevented her from that, such as marrying a non-relative or a non-Mahram of the child.
This is attested to in the following Hadith: 'Amr b. Shu'aib on his father's authority said that his grandfather (Abdullah ibn Amr ibn al-'As) reported: "A woman said: Messenger of Allah, my womb is a vessel to this son of mine, my breasts, a water-skin for him, and my lap a guard for him, yet his father has divorced me, and wants to take him away from me. The Messenger of Allah (PBUH) said: You have more right to him as long as you do not marry." {Related by Abu Dawoud}.
Ibn Qhodamah (May Allah have mercy on his soul) says: " If the couple separated and they had a child, little or retarded, then the mother has the right for custody if conditions of eligibility are ensured. This is also the opinion of Yahia al-Ansari, Al-Zuhari, Al-Thawri, Malik, Al-Shafie, Abi Thaor, Ishac, and none, that we know of, has objected to this. Another evidence is that Abu Baker granted child custody to the wife of Omar Bin Al-Khattab, and said that she is closer and softer on him than his father and stepmother. " {Al-Moghni, vol.8/ pp.190-191}.
This view was adopted by the Jordanian Civil Status Law in Article 170/2010, and the articles of this law are derived from the provisions of Islamic Law. And Allah the Almighty Knows Best.