A noun such as مَسْجِدٌ, مَدْرَسَةٌ or مَكَّةُ names a bounded place.
The usual pattern uses فِي:
جَلَسَ الطَّالِبُ فِي الْمَدْرَسَةِ — The student sat in the school.
After دَخَلَ (entered), نَزَلَ (stopped or alighted) and سَكَنَ (lived), the place can come directly without فِي and is mansub:
دَخَلْتُ الْمَسْجِدَ — I entered the mosque.
سَكَنَ زَيْدٌ الْمَدِينَةَ — Zayd lived in the city.
The verb determines which construction is used.