Instrument and place nouns can look similar, particularly when they have a prefixed mīm. Their semantic relationship to the action is nevertheless different.
WordCategoryQuestion answered
مِفْتَاحٌInstrumentWith what?
مِدَقٌّInstrumentWith what was it pounded?
مَسْجِدٌPlaceWhere did prostration happen?
مَشْرِقٌPlaceWhere does sunrise occur?
بِمِفْتَاحٍ
Translation: with a key.
فِي الْمَسْجِدِ
Translation: in the mosque.
The first phrase expresses means; the second expresses location.