Assalamualaikum ustaz. What is the ruling of a person not praying in the saf because he brought his small child with him to the mosque and doesn’t want to disturb the other congregants? Hope for an explanation.
Alhamdulillah, praise and gratitude to Allah SWT for His countless blessings for us all. Praise and salutations to our beloved Prophet Muhammad PBUH, his family, companions and all those who follow his footsteps until the Last Day.
From Anas bin Malik RA, Rasullullah PBUH said:
سَوُّوا صُفُوفَكُمْ فَإِنَّ تَسْوِيَةَ الصَّفِّ مِنْ تَمَامِ الصَّلاَةِ
“Straighten your rows. for the straightening of a row is a part of the perfection of prayer.” 
Basically, the manners of praying in congregation by ensuring that the saf is straight and filled. It is sunnah for the imam to not start the prayer before the saf is straightened and it is also sunnah to instruct the makmum behind him to straighten the saf. However, if the mosque is huge, then it is sunnah to appoint a person to ensure the saf are straightened by going around or instruction (verbally).
It is also sunnah for each who attend (in the saf) to ask for it to be filled or perfected if he sees any imperfection in the saf. The reason is it is included in amar makruf and also helping towards good and piety of which perfecting the saf is included in the perfection of prayer. 
Furthermore, it should also be understood regarding the qudwah (following the imam) conditions. According to madhhab Syafie, among them is that the makmum must know the changes of the actions of the imam. Moreover, the imam and makmum is ijtima’ (gathered) in one place. The reason is different buildings obligate iftiraq (separation of place). 
The condition of ijtima’ is different for a prayer performed in or out of the mosque. If it is in the mosque, among the conditions are that there is nothing separating the makmum to reach the imam even though he has to reverse or turn away from the qibla.
Whereas for qudwah outside the mosque for one of them, whether it is the imam or makmum is outside the mosque, the conditions are as follows:
- No separator prevents musyahadah (looking at the imam or makmum whose qudwah with the imam is valid)
- There is no barrier for istiraq (the makmum can walk to the imam without reversing or turning away from the qibla)
- Does not exceed 300 dzira’ between the imam in the mosque and the makmum outside. 
In the above issue, it is permissible to pray outside the saf in the mosque according to madhhab Syafie. However, the prioritized is to pray in the saf. The Prophet PBUH emphasizes the importance of praying in the saf, as mentioned in his statement:
مَا أَنْكَرْتُ شَيْئًا إِلَّا أَنَّكُمْ لاَ تُقِيمُونَ الصُّفُوفَ
“I have not found any change except that you do not stand in alignment in your prayers.” 
Furthermore, we also suggest the following:
- If the child is very young and it is hard to take care of him as well as distract other congregants, then it is aula (prioritized) not to be brought to the mosque.
- If the child is not distracting, however, the parents are concerned for his safety, then he can be placed beside his parents. Our advice in this situation is for the parents to pray near tphe wall (at the end of the saf) and the child is placed at the very end.
Hence, coming back to the above issue, we would like to advise you to pray beside the wall (at the end of the saf) and place your child at the very end.