Ibn Kathir in his tafsir doesn't address the meaning or possible link to the word masjid in this verse, which may mean that he considers it referring to the obvious meaning (masjid as a location or place of worship), instead he writes:
("And that you should face Him only, in every Masjid, and invoke Him only making your religion sincere to Him...'')
This Ayah means, Allah commands you to be straightforward in worshipping Him, by following the Messengers who were supported with miracles and obeying what they conveyed from Allah and the Law that they brought. He also commands sincerity in worshipping Him, for He, Exalted He is, does not accept a good deed until it satisfies these two conditions: being correct and in conformity with His Law, and being free of Shirk. (Source: qtafsir)
Al-Qurtobi in his tafsir says (My own translation take it with the necessary care):
عند كل مسجد أي في أي مسجد كنتم .
in/at every Masjid means in whatever mosque you are at.
Which is a clear link to the location.
Ibn Ashur in his at-Tahrir wa tanwir gives a definition of the word "masjid" as meant after explaining the deeper meaning of the verse and the worship in Islam (for example it is not the place that should be worshiped, but the ONE who we worship inside it) - Again my own translation take it carefully-:
ومعنى : عند كل مسجد عند كل مكان متخذ لعبادة الله تعالى ، واسم المسجد منقول في الإسلام للمكان المعين المحدود المتخذ للصلاة ...
And the meaning of "in every masjid" is at each place which was made to worship Allah (the almighty) and the names "masjid" is used in Islam to define the place specified and limited and taken to perform the prayer.
In another place he points at the fact that masjid was an innovation when calling the Ka'aba al-Masjid al-Haraam as Arabs didn't use to perform sujud (prostration) at the Ka'aba.
So "maintain yourself" is a reference to the perfect worship or complete worship, as a person who faces a direction or an other person gives full attention to this direction, person and that is what we are asked to do during worship. The whole verse is addressing and refuting the speeches of the disbelievers of the verse before who pretend that Allah has ordered them to perform or commit immorality etc. (see 7:28).
- Most other tafssirs say either the meaning of Masjid is the mosque as a place of worship or the Ka'aba as the direction we face in the prayers.
- Al-Baghawi (see here) added a meaning saying that this verse says we should prostrate only to Allah. And also a statement saying that if the time of a prayer comes one should pray at the mosque one is at and not go or say I want to pray at my (usual) mosque. Note this quoted in a known and sahih hadith (see for example sahih Muslim):
... and the earth has been made sacred and pure and mosque for me, so whenever the time of prayer comes for any one of you he should pray whenever he is ...
- A-Shwakani (see here) added a temporal meaning saying that one should face only Allah or be sincere in his worship to Allah at any times or places of prayer (worship).
- In his at-Tafssir al-Kabir, the shafi'i scholar, physician, philosoph (mutakallim) linguist and mufassir al-Fakhr ar-Razi quoted a statement attributed to ibn 'Abbas saying that if the prayer time enters one should pray at the place one actually is at (see the statement of al-Baghawi quoted before) and held the opinion that the time-related meaning is stronger than the one related to the location.
- Az-Zamakhshari in his al-Kashaaf (among the linguistic tafsirs) was of the opinion that both may apply the time of sujud or the place of sujud.
- This was also quoted by abu Hayyan al-Andalusi in his al-Bahr al-Moheet (among the linguistic tafsirs), beside the importance of the intention (due to the quotation of sincerity in the verse) for prayer and the possibility to pray anywhere based on the hadith quoted above.
- Abu Bakr al-Jassas الجصاص in his tafssir concluded two -shari'a related- meanings from this verse the first is facing the qiblah while praying the second praying in a mosque which refers -according to him- to the obligation of praying in congregation in a mosque.