Allaah has forbidden a man to be alone with a woman who is not his mahram. The Prophet (peace and blessings of Allaah be upon him) said: “No man is alone with a woman but the shaytaan is the third one present.” Narrated by al-Tirmidhi (1171); classed as saheeh by al-Albaani in Saheeh al-Tirmidhi.
Al-Bukhaari (1862) and Muslim (1341) narrated that the Prophet (peace and blessings of Allaah be upon him) said: “No man should be alone with a woman unless her mahram is with her.”
Al-Nawawi (may Allaah have mercy on him) narrated in Sharh Muslim (14/153) that there is scholarly consensus that it is haraam for a man to be alone with a non-mahram woman. This was also mentioned by al-Haafiz in al-Fath (4/77).
What is meant by a man being alone with a woman is that they are alone together in a place with no one else present.
This meaning applies when a woman travels in an elevator with a man who is not her mahram and there is no one else with them, whether it is open or closed.
Based on that, it is not permissible for a woman to travel in an elevator on her own with a non-mahram man. If there is one or more other women with her, then there is nothing wrong with her travelling on the elevator in that case, because then she is not alone with the man.
If there are both men and women with her, there is nothing wrong with her travelling on it if the elevator is spacious, and she will not be forced to touch or rub against the men. But in this case it is safer for the Muslim woman to walk up the stairs, and seek reward with Allaah for the difficulty that she encounters by doing that, because she is only doing that so as to avoid that which Allaah has forbidden and to avoid fitnah and its causes.
And Allaah knows best.