Assalamualaikum ustaz. What is the ruling if a person leaves a mosque after the adhan is called out? This means that he gets up and walks out of the mosque heading somewhere else. Hope for an explanation.
Waalaikumussalam wrt. wbt.,
Alhamdulillah, praise and gratitude to Allah SWT for His countless blessings for us all. Praise and salutations to our beloved Prophet Muhammad PBUH, his family, companions, and all those who follow his footsteps until the Final day.
We begin with the statement of Allah SWT:
إِنَّمَا يَعْمُرُ مَسَاجِدَ اللَّـهِ مَنْ آمَنَ بِاللَّـهِ وَالْيَوْمِ الْآخِرِ وَأَقَامَ الصَّلَاةَ وَآتَى الزَّكَاةَ وَلَمْ يَخْشَ إِلَّا اللَّـهَ
“The mosques of Allah are only to be maintained by those who believe in Allah and the Last Day and establish prayer and give zakah and do not fear except Allah,” 
The meaning of maintaining the mosque is by always attending it to perform worship in it in the framework of striving to attain His blessings. Among the worships are praying, reciting dhikr to Allah SWT and learning religious knowledge. Also included in the meaning is to develop the mosque by maintaining and preserving it.  A person is said to have maintained the mosque if he always attends the mosque. 
Furthermore, there are great advantages for those who perform the congregational prayer. The Prophet PBUH said:
صَلاةُ الجَماعَةِ تَفْضُلُ صَلاةَ الفَذِّ بسَبْعٍ وعِشْرِينَ دَرَجَةً
“Prayer said in a congregation is twenty-seven degrees more excellent than prayer said by a single person.” 
Likewise, there are rewards for those who are on the journey to the mosque as stated in a hadith:
فإنَّ أحَدَكُمْ إذا تَوَضَّأَ فأحْسَنَ، وأَتى المَسْجِدَ، لا يُرِيدُ إلّا الصَّلاةَ، لَمْ يَخْطُ خَطْوَةً إلّا رَفَعَهُ اللَّهُ بها دَرَجَةً، وحَطَّ عنْه خَطِيئَةً، حتّى يَدْخُلَ المَسْجِدَ
“When one of you performs ablution and does it well, then he comes to the mosque with no other motive but prayer and not seeking anything other than the prayer, he does not take one step but Allah raises him in status one degree thereby, and takes away one of his sins, until he enters the mosque. When he enters the mosque, he is in a state of prayer so long as he is waiting for the prayer.” 
Syeikh Hasan bin Ahmad al-Kaff listed several advantages of congregational prayer, among them are:
- Free and safe from hellfire.
- Safe from the attribute of a hypocrite.
- His prayers are accepted.
- His sins are forgiven.
- Greatly rewarded.
- Cures doubts and protected from shaytan. 
Leaving the Mosque After the Adhan
Coming back to the above question, there is a sahih hadith that clearly restricts the act as stated in the above question, which is from going out of the mosque after the adhan has been called out. Abu al-Sya’tha’ narrated:
كُنَّا قُعُودًا فِي الْمَسْجِدِ مَعَ أَبِي هُرَيْرَةَ فَأَذَّنَ الْمُؤَذِّنُ فَقَامَ رَجُلٌ مِنَ الْمَسْجِدِ يَمْشِي فَأَتْبَعَهُ أَبُو هُرَيْرَةَ بَصَرَهُ حَتَّى خَرَجَ مِنَ الْمَسْجِدِ فَقَالَ أَبُو هُرَيْرَةَ أَمَّا هَذَا فَقَدْ عَصَى أَبَا الْقَاسِمِ صلى الله عليه وسلم.
“We were sitting in the mosque with Abu Hurairah when the Mu’adh-dhin called the Adhan. A man got up and walked out of the mosque, and Abu Hurairah followed him with his gaze until he left the mosque. Then Abu Hurairah said: “This man has disobeyed Abul-Qasim.'” 
In another hadith, from Abu Hurairah RA, he said:
أَمَرَنَا رَسُولُ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ إذَا كُنْتُمْ فِي الْمَسْجِدِ فَنُودِيَ بِالصَّلَاةِ فَلَا يَخْرُجْ أَحَدُكُمْ حَتَّى يُصَلِّيَ
“God’s Messenger gave them this command, “When you are in the mosque and the call to prayer is made, none of you must go out before he prays.” 
Scholars have differing opinions regarding the ruling of leaving a mosque after the adhan without any excuse permitted by syarak. Some stated that it is prohibited and others said it is makruh.
In the fiqh of madhhab Hanbali, Ibn Qudamah Rahimahullan in the book al-Mughni said that it is impermissible to leave a mosque after the adhan except due to debilitation. He then presented the words of al-Imam al-Tirmizi Rahimahullah where he stated that it is the practice of scholars from amongst the companions of the Prophet PBUH and those who live after them to not leave the mosque after the adhan except because of a debilitation.  Likewise, in al-Iqna’, it is also stated that it is prohibited to leave a mosque after the adhan without a debilitation or intention to return and perform the prayer. 
Al-Imam al-Syaukani stated that both the hadiths stated above (hadith from Abu al-Sya’tha’ and Abu Hurairah) are evidences of the prohibition to leave the mosque after hearing the adhan except for those who haven’t performed the ablution, need to go for qadha’ hajat, in an exigent situation until he has prayed. 
In the fiqh book of madhhab Maliki, if a person leaves after iqamah for those who wanted to purify himself for prayer, however, he didn’t return, then it is prohibited. However, if he left after the adhan then it is makruh if his intention is to return to the mosque. However, if he left with the intention of not praying, then he is a hypocrite and it is feared that he may be struck with calamity such as what happened to some people. 
Imam al-Nawawi when commenting on the above hadith from Abu al-Sya’tha’ said that it is only makruh for those who leave the mosque after the adhan has been called out until he performs the obligatory prayer except if he experiences a debility.  The same is stated by al-Imam al-Nawawi in al-Majmu’. 
As for a debility that permits a person to leave the mosque after the adhan has been called out such as to perform ablution, where the place for ablution is outside the mosque or he leaves the mosque to return home to wake up his family members then he’ll return to the mosque or he leaves the mosque to go to another mosque because he learns about the advantages of another imam there. It is also permissible to leave if there are any exigent circumstances, severe pain or illness to seek immediate medical attention and others.
According to the above statements, we are inclined to state that it is makruh to leave the mosque after the adhan has been called out without any excuse permitted by syarak in line with the opinion of Syafi’eyyah scholars as cited by Syeikh Dr Wahbah al-Zuhaili in his book al-Fiqh al-Islami wa Adillatuh.
Although it is makruh to leave the mosque, it is best to stay in the mosque is the adhan has been called out and perform the prayer in congregation as a resolution to this issue, except if there is an excuse permitted by syarak. Wallahu a’lam.
 Surah al-Taubah : 18
 See Aisar al-Tafasir, 2/66
 See al-Tafsir al-Kabir, 5/9
 Narrated by al-Bukhari (645)
 Narrated by al-Bukhari (477) and Muslim (649)
 See al-Taqrirat al-Sadidah, pg. 289-290
 Narrated by Muslim (655)
 Narrated by al-Imam Ahmad (10933)
 See al-Mughni, 1/296
 See al-Iqna’ fi Fiqh al-Imam Ahmad bin Hanbal, 1/80
 See Nail al-Awtar, 2/192
 See al-Fawakih al-Dawani ‘ala Risalah Ibn Abi Zaid al-Qairawani, 1/172
 See al-Minhaj Syarh Sahih Muslim, 5/157
 See al-Majmu’, 2/179
 See al-Fiqh al-Islami wa Adillatuh, 1/711