In this hadeeth, when a man comes upon a gathering, he should offer greeting and he should do same when he intends to take his
leave. This is because the Prophet ﷺ ordered so and said: 'The first act of greeting is not more meritorious than the last.' That is, you should offer greeting when you intend to depart just as you did when you entered.
Thus, one sends Salam on the Prophet ﷺ when one enters the mosque and likewise when one leaves. A person performs Tawwaf when he enters Makkah for Umrah or Hajj and likewise when he is about to depart. This is because Tawwaf is the greeting of Makkah for the one who enters it with the intent of performing Hajj or Umrah. Also, the farewell greeting to Makkah for the one who came for Hajj or Umrah upon departure is Tawwaf. This is a sign of the perfection of the Sharee'ah; making the beginning same as the end in regards to these sort of matters. The Sharee'ah as we all know is from the All-Wise, All-Aware as He said:
“(This is) a Book, the verse whereof are perfected (in every sphere of knowledge, and so on) and then explained in detail from One (Allah), Who is All-wise and Well Acquainted (with all things).” (Hud: 1)
Hence, you notice order and consistency in its entirety, without contradiction nor defect. Indeed, the Messenger ﷺ prohibited that a man should walk in a single sandal, even if he is going to repair the other – why? This is because when you single out one of your feet with a sandal, it becomes oppression and injustice to the other. So, we see that the Sharee'ah of Islam commands justice in every matter:
“Verily, Allah enjoins Al-Adl (that is, Justice and worshipping none but Allah alone – Islamic Monotheism) and Al-Ihsan (that is, to be patient in performing your duties to Allah, totally for Allah's sake and in accordance with the Sunnah [Legal ways])
of the Prophet ﷺ in a perfect manner), and giving (help) to kith and Kin (that is, all that Allah has ordered you to give them e.g., wealth, visiting, looking after them, or any other kind of help, and so on.) and forbids Al-fahsha (that is, all evil deeds, e.g. illegal sexual acts, disobedience of parents, polytheism, to tell lies, to give false witness, to kill a life without right, and so on.) and Al-Munkar (that is, all that is prohibited by Islamic law: polytheism of every kind, disbelief and every kind of evil deeds, and so on.), and Al-Baghy (that is, all kinds of oppression), He admonishes you, that you may take heed.” (An-Nahl: 90)