Praise be to Allah.
Prayer in congregation is obligatory for healthy men in the mosque, according to the more correct scholarly opinion. This is based on a great deal of evidence, including the following:
1 – Allaah says (interpretation of the meaning):
“When you (O Messenger Muhammad) are among them, and lead them in As‑Salaah (the prayer), let one party of them stand up [in Salaah (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”
The following points are made on the basis of this verse:
Allaah commands them to pray in congregation, then He repeats this command a second time with regard to the second party or group, as He says, “and let the other party come up which have not yet prayed, and let them pray with you”. This indicates that prayer in congregation is an obligation for all individuals, because Allaah did not absolve the second group of this obligation as a result of the first group praying in congregation. If prayer in congregation was Sunnah, it would be more appropriate for people to be excused from it at times of fear [the situation referred to in this verse], and if it were fard kifaayah (a communal obligation), it would be discharged by the actions of the first group. So this verse shows that it is an individual obligation, and demonstrates that in three ways: it is enjoined at the beginning, then it is enjoined a second time, and there is no concession allowing them not to do it at times of fear.
From the words of Ibn al-Qayyim in Kitaab al-Salaah.
2 – In al-Saheehayn (the following version was narrated by al-Bukhaari) it is narrated from Abu Hurayrah that the Messenger of Allaah (peace and blessings of Allaah be upon him) said: “By the One in Whose hand is my soul, I had thought of ordering that wood be gathered, then I would command the call to prayer to be given, and I would appoint a man to lead the people in prayer, then I would go to men [who do not attend the congregational prayer] and burn their houses down around them. By the One in Whose hand is my soul, if anyone of you had known that he would receive a bone covered with meat or two (small) pieces of meat in a sheep’s foot, he would come for 'Isha' prayer.”
Al-Bukhaari, 7224; Muslim, 651.
Ibn al-Mundhir (may Allaah have mercy on him) said: The fact that he was thinking of burning down the houses of people who did not attend the prayer is the clearest evidence that attending prayer in congregation is obligatory, because it would not be permissible for the Prophet (peace and blessings of Allaah be upon him) to do this with regard to something that was mustahabb and not obligatory. Al-Awsat, 4/134
For more information on the evidence, please see question no. 8918.
Once it is established that prayer in congregation is obligatory, it is obligatory to perform this prayer in the mosque. It is not permissible for a man who is able to attend the congregational prayer in the mosque to pray in his house even if he prays in congregation with his family.
Shaykh Ibn Baaz said:
With regard to not praying in congregation, this is a reprehensible action and is not permitted. It is also one of the attributes of the hypocrites.
It is obligatory for the Muslim to pray in the mosque in congregation, as it says in the hadeeth of Ibn Umm Maktoom – who was a blind man. He said, “O Messenger of Allaah, I do not have a guide to lead me to the mosque,” and he asked the Messenger of Allaah (peace and blessings of Allaah 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 called him back and asked, “Can you hear the call to prayer?” He said, “Yes.” He said, “Then answer it.” Narrated by Muslim in his Saheeh, 635.
And it was narrated that the Prophet (peace and blessings of Allaah be upon him) said: “Whoever hears the call to prayer and does not come, there is no prayer for him [i.e., his prayer is not valid], unless he has an excuse.” Narrated by Ibn Maajah, al-Daaraqutni, Ibn Hibbaan and al-Haakim with a saheeh isnaad. It was said to Ibn ‘Abbaas, what is an excuse? He said, Fear or sickness.
In Saheeh Muslim (654) it is narrated that Ibn Mas’ood said: “At the time of the Messenger of Allaah (peace and blessings of Allaah be upon him) we used to think that no one failed to attend the prayer in congregation but a hypocrite or one who was sick.”
What is meant is that the believer is required to pray in the mosque, and it is not permissible for him to take the matter lightly and pray in his house when the mosque is nearby.
The fact that only two men pray in the mosque reinforces the fact that you have to attend the congregational prayer, so as to be free of any sin or shortcoming, and so as to encourage them to attend the prayer in congregation in the mosque, so that they will not get lazy. Two or more people constitutes a congregation.
Ibn Hubayrah (may Allaah have mercy on him) said: “[The scholars] were unanimously agreed that the smallest number that counts for prayer in congregation, apart from Jumu’ah prayer, is two: the imam and the person who is praying behind him, who should stand to his right.” Al-Ifsaah, 1/155
Ibn Qudaamah (may Allaah have mercy on him) said: “A congregation may consist of two or more, and we know of no difference of opinion concerning that.”
And Allaah knows best.