Making proper lines and filling the gaps is one of the essential rules of congregational prayer in Islam; for among other things, Islam, through prayer, intends to condition us to maintain discipline and organization. Therefore, the Prophet (peace be upon him) made it imperative that people organize the lines properly before the prayer begins; following him every single imam advises the people to do so.
So, no one is allowed to pray by himself, if there is a gap for him to stand in the line or any line in front of him. If he finds one he or she must join; if they do not do it deliberately, they are invalidating their prayer; they are also opposing the explicit order of the Messenger of Allah (peace be upon him).
The question, however, arises: what if someone arrives at the mosque and finds no place to stand in any of the lines in front of him; in this case, according to the majority, it is permissible for him to stand alone, but he should stand by the right side of the imam. It is important to stress that this is permissible only when there is absolutely no gap in the lines; if there is any gap in any of the lines, he should fill it, even if it requires that he walk in front of the worshippers; for it is the mistake of those in the back rows if they leave a gap in the line in front of them.
However, if he finds no gap whatsoever in any of the lines in front of him, he is excused in standing alone; this is the ruling of the majority of scholars from hanafi, maliki and shafi schools. They have based this on the hadith reported by Bukhari on the authority of Abu Bakrah that he once walked to join the salah with the Prophet (peace be upon him) and did so in a state of ruku' before reaching the line; when he later mentioned it to the Prophet he said, "May Allah increase your desire (to earn extra rewards) and but do not repeat it."
In contrast to this, the scholars of the hanbali school say no one is allowed to stand alone in a saff; if he does it, the prayer is rendered invalid. They base it on a report by Tirmidhi on the authority of Wabisah that "the Prophet (peace be upon him) ordered a person who prayed alone in a line to repeat his prayer."
However, since the Prophet did not order Bakrah to repeat the prayer, and since it is possible that Wabisah must have done it while there was still room for him in the lines in front of him, the majority view seems to be stronger.
Some of them also suggest, a person finding no room should pull someone from the line to stand beside him. One may do this; however, since it may leave the gap in the line, he may it not resort to it.
In conclusion, a person may pray alone if he finds no gap, whatsoever, in any of the lines.