All perfect praise be to Allah, The Lord of the Worlds. I testify that there is none worthy of worship except Allah, and that Muhammad is His slave and Messenger.
You are free to pray in any mosque within your city without being obliged to choose the nearest one. Praying in a distant mosque is permissible, especially if doing so leads to the advantages which you mentioned.
The jurists have handled that question and here we outline their sayings in the following points:
1. It is preferable to perform prayers in a mosque with a larger congregation, as the Prophet, sallallaahu 'alayhi wa sallam, said: “A man’s prayer offered with another man is better than his prayer which he offers alone, and his prayer with two men is better than his prayer with one and if they are more in number, it is more beloved to Allah the Almighty” [Reported by Ahmad in Al-Musnad].
2. If two mosques have equal congregant numbers, it is recommended to pray in the older one since worship in it has been more frequent.
3. If a mosque’s congregational prayer depends solely on the presence of a specific individual, it is preferable for that individual to pray there, thus helping to sustain the mosque’s function.
4. If choosing a more distant mosque would grieve the Imam of a closer mosque, it is better to pray at the nearby mosque to please its Imam.
5. When both options are otherwise equal, opinions differ: some suggest that praying in a farther mosque is preferable as it will increase the rewards one receives by increasing his steps for his journey to that mosque, while others recommend the nearer mosque, because it has the right of being the same neighbourhood. Hence, it is more worthy of performing one’s prayers in it, similar to how a neighbour has greater claims on one’s immediate kindness.
Allah knows best.