An-Nûr 24:62
إِنَّمَا الْمُؤْمِنُونَ الَّذِينَ آمَنُوا بِاللَّهِ وَرَسُولِهِ وَإِذَا كَانُوا مَعَهُ عَلَىٰ أَمْرٍ جَامِعٍ لَّمْ يَذْهَبُوا حَتَّىٰ يَسْتَأْذِنُوهُ ۚ إِنَّ الَّذِينَ يَسْتَأْذِنُونَكَ أُولَٰئِكَ الَّذِينَ يُؤْمِنُونَ بِاللَّهِ وَرَسُولِهِ ۚ فَإِذَا اسْتَأْذَنُوكَ لِبَعْضِ شَأْنِهِمْ فَأْذَن لِّمَن شِئْتَ مِنْهُمْ وَاسْتَغْفِرْ لَهُمُ اللَّهَ ۚ إِنَّ اللَّهَ غَفُورٌ رَّحِيمٌ ٦٢
Innama almuminoona allatheena amanoo biAllahi warasoolihi waitha kanoo maAAahu AAala amrin jamiAAin lam yathhaboo hatta yastathinoohu inna allatheena yastathinoonaka olaika allatheena yuminoona biAllahi warasoolihi faitha istathanooka libaAAdi shanihim fathan liman shita minhum waistaghfir lahumu Allaha inna Allaha ghafoorun raheemun
“They only are the true believers who believe in Allah and His messenger and, when they are with him on some common errand, go not away until they have asked leave of him. Lo! those who ask leave of thee, those are they who believe in Allah and His messenger. So, if they ask thy leave for some affair of theirs, give leave to whom thou wilt of them, and ask for them forgiveness of Allah. Lo! Allah is Forgiving, Merciful.” (24:62)
Asking Permission to leave when They are doing something together
This is another matter of etiquette to which Allah has guided His believing servants. Just as He commanded them to seek permission when entering, He also commanded them to seek permission when leaving, especially when they are doing something together with the Messenger , such as the Friday, `Id, or congregational prayers, or a meeting for the purpose of consultation and so on. Allah commanded them not to leave him in these situations until they had asked his permission. If they did this, then they were of the true believers. Then Allah commanded His Messenger to give permission when someone asked for it, if he wanted to. He said:
فَأْذَن لِّمَن شِئْتَ مِنْهُمْ وَاسْتَغْفِرْ لَهُمُ اللَّهَ
(give permission to whom you will of them, and ask Allah for their forgiveness.)Abu Dawud reported that Abu Hurayrah said, "The Messenger of Allah said:
«إِذَا انْتَهَى أَحَدُكُمْ إِلَى الْمَجْلِسِ فَلْيُسَلِّمْ، فَإِذَا أَرَادَ أَنْ يَقُومَ فَلْيُسَلِّمْ، فَلَيْسَتِ الْأُولَى بِأَحَقَّ مِنَ الْآخِرَةِ»
(When any of you joins a gathering, let him say Salam, and when he wants to leave, let him say Salam. The former is not more important than the latter.) This was also recorded by At-Tirmidhi and An-Nasa'i; At-Tirmidhi said: "It is a Hasan Hadith."