Is It Obligatory to Pray in the Mosque?
Question

I am a new Muslim and I want to know whether it is better for the Muslim to offer the obligatory prayers in the mosque, and what is the evidence for that?
Praise be to Allah.We praise Allah for guiding you to the religion of Islam. This is a great blessing for which Allah should be praised and thanked. 
Prayer is the greatest of the pillars of Islam
The Muslim has to understand that prayer is the greatest of the pillars of Islam, and that it is the thing which distinguishes a Muslim from a non-Muslim, as it says in the hadith of Jabir (may Allah be pleased with him) who said: I heard the Messenger of Allah (peace and blessings of Allah be upon him) say: “Between a man and shirk and kufr there stands his giving up prayer.” (Narrated by Muslim, 82) 
Is it obligatory to pray in congregation in the mosque?
The jurists (may Allah have mercy on them) differed concerning the ruling on congregational prayers. There are a number of opinions, the most sound of which is that prayer in congregation in the mosque is obligatory and this is what is indicated by the Shar`i evidence.
This is the view of ‘Ata ibn Abi Rabah, al-Hasan al-Basri, al-Awza’i and Abi Thawr, and of Imam Ahmad as it appears from some of his statements. This was also stated by al-Shafi`i in Mukhtasar al-Muzni where he said: “With regard to praying in congregation , I do not allow a concession to anyone not to do it except one who has an excuse.” This was also the view favoured by Shaykh Ibn Baz and Shaykh Ibn ‘Uthaymin (may Allah have mercy on them). 
Evidence for the obligation to pray in congregation in the mosque
With regard to the evidence that it is obligatory, it is as follows: 

Allah says (interpretation of the meaning): 

“When you (O Messenger Muhammad) are among them, and lead them in As-Salah (the prayer), let one party of them stand up [in Salah (prayer)] with you taking their arms with them; when they finish their prostrations, let them take their positions in the rear and let the other party come up which have not yet prayed, and let them pray with you” [al-Nisa 4:102]
Ibn al-Mundhir said: 
“The fact that Allah has commanded us to establish prayer in congregation even at times of fear indicates that doing so at times of security is even more obligatory.” (Al-Awsat, 4/135) 
Ibn al-Qayyim said: 
“There are several ways in which this verse may be taken as evidence: 
Firstly, Allah commands them to pray in congregation, then He repeats the command with regard to the second group, by saying “and let the other party come up which have not yet prayed, and let them pray with you”. This indicates that praying in congregation is obligatory on an individual basis, as Allah did not excuse the second group because the first group had done it. If praying in congregation was Sunnah, the best excuse for not doing it would be the excuse of fear. If it were fard kifayah (a communal obligation), it would no longer be obligatory after the first group had done it. So this verse proves that it is obligatory for each and every individual. So these are the three ways in which this verse proves it is obligatory: Allah commands it once, then He commands it again, and He does not allow them a concession not to do it at times of fear.” (Al-Salah wa Hukm Tarikiha, p. 137, 138) 

Allah says (interpretation of the meaning): 

“And perform As-Salah (Iqamat-as-Salah), and give Zakah, and bow down (or submit yourselves with obedience to Allah) along with Ar-Raki‘un (those who bow)” [al-Baqarah 2:43]
The way in which this verse may be taken as evidence is that here Allah commanded them to bow, which refers to prayer. Prayer is described as ruku’ (bowing) here because bowing is one of the pillars or essential parts of the prayer, and prayer is sometimes referred to by its pillars and obligatory components, as Allah calls it sujud (prostration), Quran and Tasbih (glorification of Allah). And the phrase “along with Ar-Raki‘un (those who bow)” cannot mean anything other than doing it with a congregation of worshippers. This is what the word ma’a (with) means. Once this is understood, if a command mentions a particular manner or situation, then the one who is commanded to do it cannot obey the command properly unless he does it in the manner or situation mentioned. Some may argue that Allah says  (interpretation of the meaning): 
“O Maryam! Submit yourself with obedience to your Lord (Allah, by worshipping none but Him Alone) and prostrate yourself, and bow down along with Ar-Raki‘un (those who bow down)” [Al ‘Imran 3:43]
But this does not mean that women have to attend prayers in congregation . It was said that this verse does not imply that this is enjoined upon all women, rather this was something that applied only to Maryam, unlike the words “And perform As-Salah (Iqamat-as-Salah), and give Zakah, and bow down (or submit yourselves with obedience to Allah) along with Ar-Raki‘un (those who bow)”. 
Maryam was a unique case, unlike other women, because her mother had vowed that she would be sacred to Allah and devoted to His worship; she would stay in the place of worship and not leave it. So she was commanded to bow with the people in the place of worship. When Allah chose her and purified her and chose her above all the women of the world, He commanded her to obey Him in ways that were unique to her and did not apply to other women. Allah says (interpretation of the meaning): 
“And (remember) when the angels said: “O Maryam (Mary)! Verily, Allah has chosen you, purified you (from polytheism and disbelief), and chosen you above the women of the ‘Alamin (mankind and jinn) (of her lifetime).” O Mary! “Submit yourself with obedience to your Lord (Allah, by worshipping none but Him Alone) and prostrate yourself, and bow down along with Ar-Raki‘un (those who bow down)”  [Al ‘Imran 3:42-43]
Some say that the fact that they were commanded to bow with those who bow does not indicate that it is obligatory to bow with them at the time when they are bowing, rather it indicates that one should do as they do, as in the verse (interpretation of the meaning): 
“O you who believe! Fear Allah, and be with those who are true (in words and deeds)” [al-Tawbah 9:119]
They further argue that the word ma’a (with) means doing the same as they do, but it does not necessarily mean doing it at the same time. The answer is that in Arabic, the word ma’a means more than doing the same as someone else, rather it means doing it with them, especially in the case of prayer. If someone says “Go and pray with the congregation ” or “I prayed with the congregation”, the only interpretation can be that he went and joined them and prayed together with them.” (Al-Salah wa Hukm Tarikiha, 139-141) 

Abu Hurayrah (may Allah be pleased with him) narrated that the Messenger of Allah (peace and blessings of Allah be upon him) said: “By the One in Whose Hand is my soul, I was thinking of ordering that wood be gathered, then I would have ordered that the call to prayer be given, then I would have told a man to lead the people in prayer, then I would have gone from behind and burned the houses of men who did not attend the (congregational) prayer down around them. By the One in Whose Hand is my soul, if any one of them had known that he would get a bone covered with good meat or two sheep’s feet with meat in them, he would have turned up for the ‘Isha prayer.” Narrated by al-Bukhari, 618; Muslim, 651 

Abu Hurayrah narrated that the Messenger of Allah (peace and blessings of Allah be upon him) said: “The most burdensome prayers for the hypocrites are ‘Isha and Fajr.  If they knew what (reward) is in them, they would come to them even if they had to crawl. I was thinking of ordering that the call to prayer be given, then I would tell a man to lead the people in prayer, and I would go out with men carrying bundles of wood to people who do not come to the prayers, and I would burn their houses with fire around them.” (Narrated by al-Bukhari, 626; Muslim, 651)
Ibn al-Mundhir said: 
“The fact that he was thinking of burning down the houses of people who stayed behind and did not attend the prayers is the clearest indication that it is obligatory to pray in congregation, because it would not have been permissible for the Messenger (peace and blessings of Allah be upon him) to burn down the houses of those who stayed behind if prayer in congregation was only something good but not obligatory.” (Al-Awsat, 4/134) 
Al-San’ani said: 
“This hadith indicates that prayer in congregation is an individual obligation, not a communal one, because if it was a communal obligation and some had done it, why would others have deserved the punishment? There is no punishment except for one who neglects an obligatory duty or does something that is haram.” (Subul al-Salam, 2/18, 19) 

Abu Hurayrah said: A blind man [Ibn Umm Maktum] came to the Prophet (peace and blessings of Allah be upon him) and said, “O Messenger of Allah, I have no one to lead me to the mosque,” and he asked the Messenger of Allah (peace and blessings of Allah be upon him) to grant him a concession allowing him to pray in his house, and he allowed him that. But when he turned away he said, “Can you hear the call to prayer?” He said, “Yes.” He said, “Then answer it.” According to a version narrated by Abu Dawud (552) and Ibn Majah (792) he said: “I do not think there is any concession for you.” 

Al-Nawawi said concerning this hadith: “Its chain of transmission is sound or good.” (Al-Majmu’, 4/164)
Ibn al-Mundhir said: 
“If there is no concession for a blind man, then it is more appropriate that there should be no concession for one who can see.” (Al-Awsat, 4/134)
 Ibn Qudamah said: 
“If there is no concession for a blind man who had no one to lead him, it is more appropriate that there should be no concession for others.”  
Al-Mughni, 2/3

Ibn Mas’ud (may Allah be pleased with him) said: Whoever would like to meet Allah tomorrow as a Muslim, let him regularly perform these prayers when the call for them is given, for they are among the ways of guidance. Allah has prescribed for your Prophet ways of guidance, and if you pray in your homes, as this one who stays away from the prayers prays in his home, then you will have abandoned the way of your Prophet, and if you abandon the way of your Prophet you will go astray. There is no man who purifies himself and does it well, then he goes to one of these mosques, but for every step he takes, Allah will record for him one good deed and will raise him thereby one degree in status, and will erase for him one bad deed. I saw us (at the time of the Prophet (peace and blessings of Allah be upon him)) and no one stayed behind from these prayers except a hypocrite who was known for his hypocrisy. A man would come supported by two others so that he could stand in the row. 

According to another version, he said: The Messenger of Allah (peace and blessings of Allah be upon him) taught us the ways of guidance, and told us that one of the ways of guidance is to pray in the mosque when the call to prayer is given. (Narrated by Muslim, 654) 
Ibn al-Qayyim said: 
“What we may conclude from this is that he described staying away from the prayers as one of the signs of the hypocrites who are known for their hypocrisy. The signs of hypocrisy are not omitting mustahabb actions or doing makruh things. Whoever seeks to learn the signs of hypocrisy according to the Sunnah will find that they are omitting obligatory actions or doing haram things. This is supported by the fact that he said: “Whoever would like to meet Allah tomorrow as a Muslim, let him regularly perform these prayers when the call for them is given”. And he described the one who stays away and offers the prayers at home as being one who has abandoned the Sunnah which is the path of the Messenger of Allah (peace and blessings of Allah be upon him) and the laws that he prescribed for his ummah. What is meant is not the Sunnah which those who wish can do and those who do not wish can omit, because omitting that is not misguidance or a sign of hypocrisy – such as not praying Duha and qiyam al-layl, or fasting on Mondays and Thursdays.” (Al-Salah wa Hukm Tarikiha, p. 146, 147) 

The consensus of the Companions 

Ibn al-Qayyim said: 
“There was consensus among the Companions and we will quote what they said: 
We have mentioned the words of Ibn Mas’ud above: “I saw us (at the time of the Prophet (peace and blessings of Allah be upon him)) and no one stayed behind from these prayers except a hypocrite who was known for his hypocrisy.” 
It was also narrated that Ibn Mas’ud (may Allah be pleased with him) said: “Whoever hears the muadhdhin and does not respond with no excuse, his prayer is not valid.” 
Abu Musa al-Ash’ari said: “Whoever hears the muadhdhin and does not respond with no excuse, his prayer is not valid.” 
`Ali said: “There is no prayer for a neighbour of the mosque except in the mosque.” It was said, “Who is the neighbour of the mosque?” He said, “Whoever can hear the muadhdhin.” 
Al-Hasan ibn ‘Ali (may Allah be pleased with him) said: “Whoever hears the call to prayer and does not come, his prayer does not go beyond his head, except for one who has an excuse.” 
`Ali (may Allah be pleased with him) said: “Whoever among the neighbours of the mosque hears the call to prayer, and he is in good health and does not have any excuse, his prayer is not valid.” (Al-Salah wa Hukm Tarikiha, p/ 153) 
There is a great deal of evidence, but what we have quoted above is sufficient. You can refer to the book by Ibn al-Qayyim, al-Salah wa Hukm Tarikiha (Prayer and the Ruling on one who abandons it), which has a lot more information. Shaykh Ibn Baz wrote a useful essay entitled Wujub Ada al-Salah fi Jama’ah (The obligation of offering prayers in congregation).  
For more, please see this category: Congregational Prayer
And Allah knows best.