Question: 

Is the salah invalid for the one praying alone behind the first or second line?

Answer:

The Lajnah (Permanent Committee For Scholarly Research And Ifta’) were asked:
Q: Is the Salah (Prayer) of a person who stands alone behind a row in congregational Salah valid? Is it permissible for one to draw a person from the first row so as not to stand alone in congregational Salah? 

A: It is not permissible for a person to offer Salah while standing alone behind the row during congregational Salah, as it renders the Salah invalid according to the Hadith of the Prophet (peace be upon him): There is no Salah (valid) for a person who offers it while standing alone behind the row (in congregational Salah). Moreover, the Prophet (peace be upon him) saw a man praying alone behind the row and he (peace be upon him) ordered him to repeat the Salah.

A Muslim should look for a gap in a row to stand in and if there is none, he may, if possible, stand right to the Imam. Otherwise, the worshipper should wait until someone comes so that both of them can form a row. If the congregational Salah ends and none has come, he or she must offer it individually. It is necessary for every Muslim to hasten to congregational Salah in the Masjid and be keen to join it from the beginning with other worshippers. Allah (Exalted be He) says: Guard strictly (five obligatory) As-Salawât (the prayers) especially the middle Salât (i.e. the best prayer – ‘Asr). And perform As-Salât (Iqâmat-as-Salât), and give Zakât and bow down (or submit yourselves with obedience to Allâh) along with those who bow down (in prayer). The Prophet (peace be upon him) stated: Anyone who hears the call (to Salah) and does not come to it, then there is no Salah (valid) for him except with an excuse. It was said to Ibn `Abbas (may Allah be pleased with them both), “What is the excuse?” He said, “Fear or illness.”

It is authentically reported that a blind man asked the Prophet (peace be upon him) saying: ‘O Messenger of Allah! I have no one to lead me to the Masjid. Am I permitted to offer Salah at home?’ The Prophet (peace be upon him) said to him, ‘Do you hear the call to Salah (Adhan)?’ He said, ‘Yes.’ The Prophet (peace be upon him) said, ‘Then, respond.’ (Related by Imam Muslim in his Sahih [Authentic Hadith Book]) There are many Hadiths that corroborate this meaning.

[Reference]

However, there issome differing around the matter; the scholars have mentioned one doesn’t take one out of the row to join him as is well known. But, what if a man enters the masjid and the row is packed and no space to join at all and he can’t reach the right of the imam to pray beside him? In this case, some of the scholars such as Imam Albani, The former Mufti Muhammad Ibn Ibraheem, shaykh al Uthaymeen and others held the stance that he is excused in this situation if he tried and there’s no room because Allah says:

Fear Allah to the best of your capabilities

Now if he doesn’t try and just says “I will just pray alone” then in this case it is different,

Mentioned by

Majid Jawed Al-Afghanee
Abu Layl