All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad, sallallaahu ‘alayhi wa sallam, is His slave and Messenger.
Dear questioner, you should know that Muslims are allowed to perform prayer anywhere and that every spot of the earth is considered an apt place for performing prayer; the whole earth is a mosque. The due Islamic rulings with regard to mosques are to be applicable to any place as soon as one intends to perform the prayer in it. A mosque is not merely the building intended to be a place of worship. The word "Masjid" (i.e. mosque) in the Islamic terminology does not necessarily refer to a building.
The Masjid of the Prophet, sallallaahu ‘alayhi wa sallam, had a building and an area without buildings and the whole place belonged the mosque. The rewards for the prayer therein are multiplied and the worshipper should perform the prayer of Tahiyyat-ul-Masjid upon entering any part of it.
Therefore, Muslim scholars said that the mosque's courtyard is considered a part of the mosque if it was intended to be so.
Hence, there is no harm in performing the congregational prayer outside the complex of the mosque as long as the place where the congregational prayer is performed is considered a part of the mosque. The worshipper can perform the prayer of Tahiyyat-ul-Masjid anywhere in the mosque, whether in the mosque's main building or in its courtyards.