Fiqh-us-Sunnah Volume 2, Supererogatory Prayer, Fiqh 2.051.

Section : Praying at a larger and more distant mosque.

It is preferable to pray in a mosque that is farther away and that has a larger congregation.

Muslim records from Abu Musa that the Prophet sallallahu alehi wasallam said: “The one who gets the greatest reward for a prayer is the one who walks the farthest distance.” Muslim also records that Jabir said: “The area around the mosque became vacant and the tribe of Salamah wanted to move there. When this news reached the Messenger of Allah, he said: ‘It has reached me that you want to move closer to the mosque?’ They said: ‘Yes, O Messenger of Allah, we desire that.’ The Prophet said: ‘O tribe of Salamah, your dwellings will record your steps.'” Al-Bukhari, Muslim, and others have recorded this on the authority of Abu Hurairah.

Ubayy ibn Ka’b reported that the Prophet sallallahu alehi wasallam said: “The salah of a man with another man is purer than the salah of a man by himself. [In the same way,] his salah with two men is purer than his salah with only one man, and what is more, it is most dear to Allah.” This is related by Ahmad, Abu Dawud, an-Nasa’i, Ibn Majah and Ibn Hibban. Ibn as-Sakin, al-‘Uqaily and al-Hakim classify it as sahih.