It is obligatory to attend prayers in congregation at a Mosque as can be seen from the following hadith:
It was narrated from Abu Hurayrah (may Allaah be pleased with him)
that the Messenger of Allaah (peace and blessings of Allaah 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-Bukhaari, 618; Muslim, 651
From Quran:
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”
[al-Nisa’ 4:102]
Ibn al-Mundhir said:
The fact that Allaah 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.
According to the Sahabas , Prayers of the neighbors of Mosque are not valid except inside the Mosque:
It was also narrated that Ibn Mas’ood (may Allaah be pleased with him)
said: “Whoever hears the muezzin and does not respond with no excuse,
his prayer is not valid.”
It was narrated that Abu Moosa al-Ash’ari said: “Whoever hears the
muezzin and does not respond with no excuse, his prayer is not valid.”
It was narrated that ‘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 muezzin.”
It was narrated that al-Hasan ibn ‘Ali (may Allaah 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.”
It was narrated that ‘Ali (may Allaah 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-Salaah wa Hukm Taarikiha, p/ 153
Even a blind man who could hear Meuzzin was not given concession:
It was narrated that Abu Hurayrah said: A blind man [Ibn Umm Maktoom]
came to the Prophet (peace and blessings of Allaah be upon him) and
said, “O Messenger of Allaah, I have no one 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 said, “Can you
hear the call to prayer?” He said, “Yes.” He said, “Then answer it.”
According to a version narrated by Abu Dawood (552) and Ibn Maajah
(792) he said: “I do not think there is any concession for you.”
Al-Nawawi said concerning this hadeeth: its isnaad is saheeh or hasan.
Al-Majmoo’, 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.
So if you have no valid excuse to not go to the Mosque for congregation prayers and you can hear the Muezzin , then prayers at home are not valid as per the above fatwas and hadith.
Apart from the generic view above there are certain cases where prayer in congregation would be frowned upon, or even completely discouraged:
'And the mosques are for Allah (Alone), so invoke not anyone along
with Allah.' [Soorah al-Jinn (72): 18]
The Prophet (peace be upon him) in this regard says: “Prayer is not
valid when food has been served and when a person is in need of
relieving himself of excrement and/or urine” (Reported by Imam
Muslim).
Allah Knows Best