The obligation to make the rows straight in prayer and the meaning thereof
Question

Is straightening the rows in congregational prayers obligatory in the sense that the worshippers are sinning if they do not make their rows straight?.
Praise be to Allah.Firstly: 
Islam pays a great deal of attention to the rows of worshippers, as it has enjoined straightening the rows and speaks clearly of the virtue and importance of straightening them. 
It was narrated from Anas ibn Malik (may Allah be pleased with him) that the Prophet (peace and blessings of Allah be upon him) said: “Straighten your rows, for straightening the rows is part of perfecting prayer.” Narrated by al-Bukhari, 690; Muslim, 433. According to another report narrated by al-Bukhari (723): “Straighten your rows, for straightening the rows is part of establishing prayer.” 
It was narrated that Abu Mas’ood (may Allah be pleased with him) said: The Messenger of Allah (peace and blessings of Allah be upon him) used to touch our shoulders when we were praying and he would say: “Make the rows straight and do not differ, lest your hearts differ.” Narrated by Muslim, 432. 
It was narrated that al-Nu’maan ibn Basheer (may Allah be pleased with him) said: The Messenger of Allah (peace and blessings of Allah be upon him) used to straighten our rows, as if he was straightening the shaft of an arrow, until he saw that we had learned it. Then he came out one day and was about to say the takbeer, when he noticed a man whose chest was sticking out from the row. He said: “Slaves of Allah! Make your rows straight or Allah will cause discord among you.” Narrated by al-Bukhari, 717; Muslim, 436.  
Al-Nawawi said in Sharh Muslim: 
With regard to the phrase “[he] used to straighten our rows, as if he was straightening the shaft of an arrow”, the qadaah is the wooden shaft of the arrow where it is pared and trimmed, i.e., he paid such great attention to straightening the rows, as if he was straightening the shaft of an arrow, because they were so straight. End quote. 
These texts clearly show that it is obligatory to straighten the rows. Al-Bukhari (may Allah have mercy on him) said in his Saheeh: “Chapter: The sin of those who do not complete the rows”, in which he narrated with his isnaad from Bushayr ibn Yasaar al-Ansaari from Anas ibn Malik that he came to Madeenah and it was said to him: What do you find has changed in us since the time of the Messenger of Allah (peace and blessings of Allah be upon him)? He said: I do not find anything except that you do not straighten your rows. Narrated by al-Bukhari, 724. 
Al-Haafiz ibn Hajar said in Fath al-Baari: This is to be understood as meaning that al-Bukhari understood it to be obligatory from the form of command in the words of the Prophet (peace and blessings of Allah be upon him): “Straighten your rows,” and from the general meaning of his words, “Pray as you have seen me praying,” and from the warning issued against failing to do that. So in his view, on the basis of this evidence,  Anas was criticizing a failure to do something that is obligatory, although a criticism may also come for failing to do something that is Sunnah. Although straightening the rows is obligatory, the prayer of those who fail to do that and do not straighten their rows is still valid. That is supported by the fact that although Anas criticized them, he did not tell them to repeat their prayer. End quote. 
Shaykh Ibn ‘Uthaymeen (may Allah have mercy on him) said: 
The words “or Allah will cause discord among you” … this is undoubtedly a warning to those who fail to straighten their rows. Hence some of the scholars are of the view that it is obligatory to make the rows straight. They quoted as evidence for that the fact that the Prophet (peace and blessings of Allah be upon him) enjoined it and warned those who went against his command. If something is enjoined and a warning issued against doing the opposite, it cannot be said that it is “only Sunnah”. 
Hence the correct view on this matter is that it is obligatory to straighten the rows, and if the congregation does not straighten the rows, then they are sinning. This is the apparent meaning of the words of Shaykh al-Islam Ibn Taymiyah."(Al-Sharh al-Mumti’, 3/6)
Straightening the rows is obligatory so that no one will stand in front of anyone else, whether that is by his chest or his foot sticking out. 
It says in ‘Awn al-Ma’bood: 
What is meant by straightening the rows is for the people standing in the row to make a straight line. End quote. 
Shaykh Ibn ‘Uthaymeen (may Allah have mercy on him) said: 
Straightening the rows means that no one stands in front of anyone else, but is what is meant that the foot should not be in front of anyone else’s foot? The answer is that what is meant is the shoulders at the top of the body, and the heels at the bottom of the body. 
Attention is paid to the heels because they are the foundation on which the body rests. The heel is at the bottom of the leg, and the leg is the pillar of the body, so this is what matters. As for the toes, they do not count, because toes vary; some people have long feet and some have short feet, so what matters is the heel. 
There is another kind of straightening that means completeness or perfection, as Allah says (interpretation of the meaning): 
“And when he attained his full strength, and was perfect (in manhood)” [Al-Qasas 28:14]
Here the word astawa (translated as ‘was perfect’) means: was made complete. If we say istiwa’ al-sufoof (straightening of the rows) in the sense of completeness, that does not detract from the meaning of straightening them in the sense of ensuring that everyone stands parallel, rather it encompasses a number of meanings: 
1 – Straightness in the sense of standing parallel, which according to the correct view is obligatory, as stated above. 
2 – Making the rows compact, which is part of making them complete or perfect. The Prophet (peace and blessings of Allah be upon him) used to enjoin that, and he urged his ummah to form rows as the angels do before their Lord, filling in and completing the rows one by one. But what is meant by making the rows compact is not leaving gaps for the devils; it does not mean crowding and cramming people in, because there is a difference between making it compact and making it crowded. Hence the Prophet (peace and blessings of Allah be upon him) used to say: “Make the rows straight, and make the shoulders parallel… and do not leave gaps for the devils.” 
i.e., there should be no gaps between you through which the devils can enter, because the devils enter among the rows like small lambs so that they can spoil the prayer of the worshippers. 
3 – Completing the first row and then the next. This is part of straightening the rows. The second row should not be begun until the first row is completed, and the third row should not be begun until the second row is completed, and so on. The Prophet (peace and blessings of Allah be upon him) urged completing the first row and said: “If the people knew what there is in the call and the first row, but they had no way other than drawing lots, then they would draw lots.” I.e., if two people came to the first row and one of them said, “I am more entitled to it than you,” and the other said, “I am more entitled,” and he said: “Let us draw lots to see which of us will be in this spot.” 
One of the ways in which the Shaytaan plays with people nowadays is when they see that the first row is only half full, but despite that they start the second row, then when the iqaamah is given, and it is said to them,  “Complete the first row,” they start looking around in confusion. 
4 – Another aspect of straightening the rows is making the rows close to one another and close to the imam, because they are a jamaa’ah (congregation, group) and the word jamaa’ah is taken from the word ijtimaa’ (coming together). There can be no proper coming together if the rows are far apart. The closer the rows are to one another and to the imam, the better it is. In some mosques we see gaps between the imam and the first row that are so wide that another row or two could fit in, because the imam goes so far forward. I think that this stems from ignorance. The Sunnah is for the imam to be close to the people who are praying behind him, and the people should be close to the imam, and each row should be close to the other. The definition of close is that there should be enough room between them to prostrate and a little more. 
5 – Another aspect of straightening the rows is to draw close to the imam, because the Prophet (peace and blessings of Allah be upon him) said: “Let those among you who are men of wisdom and understanding be closest to me.” The closer the better. Hence it is encouraged to draw close to the imam in Jumu’ah prayers, because drawing close to the imam in Jumu’ah prayers is achieved by drawing close to him during the prayer and during the khutbah. Drawing close to the imam is something desirable, but some people are negligent concerning that and are not keen to do it. 
6 – Another aspect of straightening the rows is preferring the right hand side of the row to the left, i.e., the right side of the row is better than the left, but that is not in absolute terms, as in the case of the first row, because if it was in absolute terms, as in the case of the first row, the Messenger (peace and blessings of Allah be upon him) would have said, “Complete the right side then the right side,” as he said, “Complete the first row then the next.” The right side is better than the left if both right and left are roughly equal, such as if there are five on the right and five on the left, then the eleventh man comes. In that case we tell him: Go to the right, because the right is better when both sides are equal or almost equal, such that the difference between the right and left is not obvious. But if there is a difference, then undoubtedly the left side of a closer row is better than the right side of a more distant row. This is indicated by the fact that if the congregation is just three people, the imam should stand between them, i.e., between the other two. This indicates that the right is not better in absolute terms, because if it were better in absolute terms, it would be better for the two people to stand on the right of the imam, but what is prescribed is that one should be on the right and one on the left so that the imam is in the middle and there is no imbalance on one side. 
7 – Another aspect of straightening the rows is that the women should stand on their own, i.e., the women should be behind the men, not mixed with the men, because the Prophet (peace and blessings of Allah be upon him) said: “The best rows for men are the first rows and the worst are the last, and the best rows for women are the last rows and the worst are the first.” The Prophet (peace and blessings of Allah be upon him) stated that the further women are behind the men, the better. 
So it is better for women to be far behind the men, because of the fitnah involved in their being close to men. Worse than that is their mixing with the men, where a woman would be beside a man or a row of women would be between two rows of men. This is not appropriate and as well as being haram there is the fear of fitnah. 
It is more likely to be haram when there is the fear of fitnah, but even when there is no fitnah, this is still not appropriate, such as if the women are mahram of the men."(Al-Sharh al-Mumti’, 3/13-17).