Assalaamu alaykum. Suppose that there is only one door and that door is beside the first row of a prayer hall. Some space has to be kept in the far right side of the first row in order to be able to pass. If someone comes and stands alone in the second row though there is space for one man to stand in the first row given that he has to leave space so that other people may pass, is his prayer valid?
All perfect praise be to Allah, The Lord of the worlds. I testify that there is none worthy of worship except Allah and that Muhammad, sallallahu ‘alayhi wa sallam, is His slave and Messenger.
The prayer of that person is valid, and the prayer of the person who prays in a row alone behind the rows is also valid, although disliked. This is the view held by the majority of scholars, and it is the one adopted at Islamweb. The dislike is removed when there is a valid excuse. There is no doubt that leaving an empty space for the worshipers to enter the mosque is a valid excuse for standing in a row by yourself during the congregational prayer.
For more benefit, please refer to fatwa 31530.
Allah knows best.
You can search for fatwa through many choices