For example, a person leaves the masjid. That is, he passes the wall of the masjid a little to buy medicine, (and) then he returns immediately. Does he have to pray the tahiyyatul masjid here [in this case]?
He was sitting in the masjid?
Yes sitting in the masjid.
Then he left?
He came out. He passed the wall of the masjid a little.
Then he must whether he leaves a little or a lot, as long as he leaves the masjid. Then (in that case) he must pray tahiyyatul masjid before sitting
[Mutafarriqaat no. 1]
Faisal Ibn Abdul Qaadir Ibn Hassan