Reference: Majmoo’ Fataawa Ibn ‘Uthaymeen – Volume 12, Page 200
Question: What is the ruling regarding leaving the masjid after the adhaan has been called?
Response: Abu Hurayrah saw a man leave [the masjid] after the adhaan [had been called] and said [about him]:
«As for this [one], then he has gone against [the teachings of] Abul-Qaasim ﷺ», transmitted by Muslim.
And to go against [the teachings] principally is prohibited. Allaah (Subhaanahu wa Ta’aala) says:
{It is not for a believer, man or woman, when Allaah and His Messenger have decreed a matter that they should have any option in their decision. And whoever disobeys Allaah and His Messenger, he has indeed strayed in a plain error}, Soorah al-Ahzaab, Aayah 36
So, because of this, the people of knowledge have said: Indeed it is not permissible for a person to leave the masjid after the adhaan [has been called] except for a [Islaamically justifiable] reason, such as leaving to make wudhoo and then return, and if he wanted to go to answer the call of nature, then he is permitted to leave, even if he misses the prayer as the prophet ﷺ said:
«There is no prayer if food has been served or for him who needs to answer the call of nature», transmitted by Muslim.
So, if we say that someone is waiting for the prayer and then felt the need to go and answer the call of nature or even to pass wind, since some people [may be in] need of passing wind, then there is no harm if he left and relieved himself [and] then returned.
And if he was able to [catch and] join the congregation, then it is a blessing, and if he was unable to do so, then there is no harm in this.