Shaikh Ibn ul-‘Uthaymeen rahimahullah said:

“As for the one who exits from the masjid then returns soon, then he does not pray tahiyyatul Masjid because he did not leave with a leaving that is interrupted. So like this, it was not reported from the Messenger sallahu alayhi wa salam that when he exited to go to his house for a need and he was in ‘Itikaaf (and) then returned, that he prayed two rakat. Also, this exiting is not considered exiting by the evidence that it does not break the Itikaaf of the one in Itikaaf. If his exiting is considered separating from the masjid, then his itikaaf would be broken. So like this, if a person exited from the masjid with an intention not to return except for the following obligatory prayer, then after taking some steps, he returns to speak to another person (for) even after half a minute, then this one prays two rakat because he left with the intention of leaving that being interrupted/suspended”

[Majmoo al-Fatawa wa Rasaail (14/352)]

Translated by

Faisal Ibn Abdul Qaadir Ibn Hassan
Abu Sulaymaan