Man offers prayer behind a woman but not as mamum
Assalamu Alaikum We know as a rule that women stand behind men in prayer. My question is: If a woman is praying her nafl prayer in the front part of a room, and while she is praying, her mahram (husband, father, etc) also enters the room to pray fard or nafl, is it allowed for him to stand to do his prayer behind her? I do not mean having her as imam of course, I mean the fact that he stands behind her. What if the man is non-mahram? Should she stop praying and walk out regardless of whether she is praying fard or nafl, as in Islam it is haram for a man and woman to not be alone in a room? What should she do? Jazak Allah