On the occasion of the Battle of Tabook, when Rasulullah (sallallahu ‘alaihi wasallam) was departing from Madinah Munawwarah, he appointed Hazrat Ali (radhiyallahu ‘anhu) to oversee the affairs of Madinah Munawwarah in his absence.
Hence, on the instruction of Rasulullah (sallallahu ‘alaihi wasallam), Hazrat Ali (radhiyallahu ‘anhu) did not go out with the army, but rather he remained in Madinah Munawwarah.
Thereafter, certain people began to spread rumors that the reason why Rasulullah (sallallahu ‘alaihi wasallam) had told Hazrat Ali (radhiyallahu ‘anhu) to remain behind was that he was displeased with him. Hearing this, Hazrat Ali (radhiyallahu ‘anhu) immediately came to Rasulullah (sallallahu ‘alaihi wasallam) and mentioned to him what certain people were saying.
According to one narration, Hazrat Ali (radhiyallahu ‘anhu) said to Rasulullah (sallallahu ‘alaihi wasallam), “O Rasul of Allah (sallallahu ‘alaihi wasallam)! I do not want the Arabs to say regarding me, ‘He has abandoned his cousin (Rasulullah (sallallahu ‘alaihi wasallam)) and remained behind.’”
Furthermore, it was the deep desire of Hazrat Ali (radhiyallahu ‘anhu) to join the army so that he could strive in the path of Allah Ta‘ala. According to another narration, Hazrat Ali (radhiyallahu ‘anhu) said to Rasulullah (sallallahu ‘alaihi wasallam), “O Rasul of Allah (sallallahu ‘alaihi wasallam)! Are you leaving me behind with the women and children?”
Rasulullah (sallallahu ‘alaihi wasallam) consoled him and said to him, “Are you not pleased that your position with me will be like the position of Haroon with Moosa (alaihimas salaam), except that there will be no nabi to come after me?”
In other words, when Nabi Moosa (‘alaihis salaam) went to Mt Toor, he left his brother, Nabi Haroon (‘alaihis salaam), in charge of the people. This indicated the high rank of Nabi Haroon (‘alaihis salaam) and the trust and confidence that Nabi Moosa (‘alaihis salaam) had in him.
In the same way, Rasulullah (sallallahu ‘alaihi wasallam) informed Hazrat Ali (radhiyallahu ‘anhu) that appointing him over the affairs of Madinah Munawwarah in his absence was a sign that Rasulullah (sallallahu ‘alaihi wasallam) had confidence in him.
When Hazrat Ali (radhiyallahu ‘anhu) heard this, he immediately said, “I am pleased, I am pleased (with the decision of Allah Ta’ala and His Rasul (sallallahu ‘alaihi wasallam)).” (Saheeh Muslim #2404, Majma’uz Zawaa’id #14642 & 14653 and Fat-hul Baari 7/86)