Within the Sunan of Imām ibn Mājah رحمه الله (d. 273 AH/886 CE), theres a report attributed to The Prophet ﷺ that some people may quote regarding the impermissibility of keeping young children or babies in Masājid. It is as follows:
Keep your infants, your insane, and your evil ones away from your Masājid. Avoid engaging in transactions and disputes, raising your voices, carrying out your prescribed punishments, and unsheathing your swords therein. Make places for purification at their gates, and perfume them with incense on al-Jumuʿah.Sunan ibn Mājah #750
However, theres another Ḥadīth attributed to The Prophet ﷺ that contradicts the action of not having young children in Masājid which has a Ṣaḥīḥ Isnād (authentic chain of narration) attached to it. As follows:
Anas ibn Mālik رضي الله عنه narrated:
One day, The Prophet ﷺ prayed Fajr and he made it short. The Companions asked: ‘O Messenger of Allāh, why did you shorten the prayer?’ He ﷺ responded: ‘I heard a child crying and I assumed his mother was praying with us, so I wanted to free his mother for him.’Kitāb al-Maṣāḥif 4/14/2
*Note: this Ḥadīth indicates the kindness of our beloved Prophet ﷺ & that one should shorten their prayer if it would lessen burdens of others.
So, is the Ḥadīth reported in Sunan ibn Mājah something to be practiced? Are children actually supposed to be kept away from Masājid? How authentic is this Ḥadīth? — Such will be explained in the following citations:
Shaykh Muḥammad Nāṣir ad-Dīn al-Albānī رحمه الله (d. 1420 AH/1999 CE) said regarding the Ḥadīth of Anas ibn Mālik رضي الله عنه: “This Ḥadīth and other Aḥādīth stand as evidence supporting the permissibilty of having children in the Masjid. As for the report that laypeople often quote: ‘Keep your children away from the Masjid’, it is a Ḍaʻīf (weak) report that cannot be used as evidence by Ijmāʿ. Among the scholars who graded the report Ḍaʻīf are ibn al-Jawzī, al-Mundhirī, ibn Ḥajar al-ʿAsqalānī, al-Busayrī, and ʿAbd al-Haqq al-Ishbilī who said it is baseless.” 
Shaykh Zubayr ʿAlī Zay رحمه الله (d. 1434 AH/2013 CE) said it’s Isnād is Mawḍūʾ (fabricated) as within it is Abū Saʾīd al-Maṣlūb, who was deemed a Kadhāb (liar). 
We now come to the conclusion that this report is a weak Ḥadīth with no basis & it is in fact permissible to bring young children to our Masājid, and Allāh knows best.
May Allāh have abundant mercy upon Shaykh Muḥammad Nāṣir ad-Dīn al-Albānī, Shaykh Zubayr ʿAlī Zay, the compilers of the books referenced, & reward them all for their many contributions to the religion of Islām.
All praise is due to Allāh, may His peace & blessings be upon our final Prophet Muḥammad, his family, his companions, & all those who follow him in guidance.
Ṣafīullāh Labīb ibn Salīm ʿAbd al-Malik
14th of Muḥarram 1444