Answer:
When intending to remain in a mosque for certaing period for worship. This is called "Al-E3tekaf" or "الاعتكاف" and those wroshipers are called عاكفون "akefoun"
In Quran:
وَلَا تُبَاشِرُوهُنَّ وَأَنتُمْ عَاكِفُونَ فِي الْمَسَاجِدِ ۗ تِلْكَ حُدُودُ اللَّـهِ فَلَا تَقْرَبُوهَا ۗ كَذَٰلِكَ يُبَيِّنُ اللَّـهُ آيَاتِهِ لِلنَّاسِ لَعَلَّهُمْ يَتَّقُونَ ﴿١٨٧﴾
"...And do not have relations with them as long as you are staying for worship in the mosques. These are the limits [set by] Allah, so do not approach them. Thus does Allah make clear His ordinances to the people that they may become righteous. (187)"
(Quran, chapter 2, verse 187)