Answered by Sidi Abu Yahya
If one is praying in a room alone and during the prayer and a non-mahram enters the room, should we continue to pray?
2. Is being in an elevator with a non-mahram permissible? More generally, what are the rules regarding seclusion with non-mahram?
Seclusion, or “khalwa” occurs when a man and a non-mahram women are alone in an enclosed area, such as a room with the door closed (even if unlocked), and such as an elevator. It is no longer “khalwa” if a second women enters, or another man who is mahram to the woman. However, if a third man enters who is not her mahram, it is still considered “khalwa”. Even if there are many men, it remains “khalwa” until another woman enters or a man who is her mahram. This is the position of the Shafi’ school. If you are praying and a non-mahram woman enters the room and closes the door, there definitely is a problem. As to whether you should speed up your prayer and then leave or if you should actually interrupt it immediately and leave is something I need to investigate further. It would also depend on whether the prayer was an obligatory prayer, or a nafl prayer.