Sahih al Bukhari
Volume 5, Book 59, Number 700:
Narrated Sad: Allah’s Apostle set out for Tabuk. appointing ‘Ali as his deputy (in Medina). ‘Ali said, “Do you want to leave me with the children and women?” The Prophet said, “Will you not be pleased that you will be to me like Aaron (Harun) to Moses (Musa)? But there will be no prophet after me.”
Translated by some like this: (‘Your relation to me shall be like the relation of Harun to Musa…) & (You hold in relation to me the same position as Harun held in relation to Musa)
Hadith in Arabic:
عَنْ مُصْعَبِ بْنِ سَعْدٍ عَنْ أَبِيهِ أَنَّ رَسُولَ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ خَرَجَ إِلَى تَبُوكَ وَاسْتَخْلَفَ عَلِيًّا فَقَالَ أَتُخَلِّفُنِي فِي الصِّبْيَانِ وَالنِّسَاءِ قَالَ أَلَا تَرْضَى أَنْ تَكُونَ مِنِّي بِمَنْزِلَةِ هَارُونَ مِنْ مُوسَى إِلَّا أَنَّهُ لَيْسَ نَبِيٌّ بَعْدِي
This hadith is not evidence of khilafah of Ali radiyallahu anhu after the death of the Prophet sallallahu alayhi wa sallam, because the comparison is with Haroon alayhi assalam, and Harun alayhi assalam died before Musa alayhi assalam and thus was never his successor after him.The following is an explanation by al Qurtubi -rahimahu Allah- in his tafsir (tafseer of ayah 2:30) regarding this narration:
[There is no disagreement that the Prophet -sallallahu alayhi wa sallam- didn’t mean, by (saying) “you will be to me like Harun (Aaron) to Moses” the khilafah after him, and there is no disagreement that Haroon died before Musa -alayhima assalam- … and was not a khalifah after him, for the khalifah (successor of Musa) was Yusha’ bin Noon, so if he wanted by his saying “you will be to me like Harun to Moses” the khilafah, he would have said “you will be to me like Yusha’ was to Musa“, so when he didn’t say this it proved that he didn’t want that meaning, but he wanted that “you are my deputy over my family in my life and my abscence from my family, like Harun was deputy of Musa over his people when he left to speak to his Lord.]
Other scholars of ahl assunah explained it the same, him being deputy of the Prophet -sallallahu alayhi wa sallam – over the women and children when he went to the battle of Tabuk just like Musa -alayhi assalam- left Harun -alayhi assalam- as his deputy when he went to his appointment with Allah ta’ala.
In a Shia site it says:
((To this we answer that whenever the Prophet, peace and blessings be upon him and his family, left the Islamic capital, he would always appoint someone to act as his deputy. If by comparing Ali, peace be upon him, to Harun, the Prophet, peace and blessings be upon him and his family, had intended nothing more than the usual appointment of a deputy, restricted in his authority to Madinah for the period of the Prophet’s absence, why did he not use a similar expression for those other favored Companions he would appoint as deputy? Why did he not use the same or similar words to describe the services they rendered?))
Answer: Those sahabah might have not asked the Prophet sallallahu alayhi wa sallam to go with him and not stay behind to watch who is left behind from women, children and others, so there was no need for him to tell them that, but Ali radiyallahu anhu objected to staying behind with children and women and not go to fight with the Prophet sallallahu alayhi wa sallam, and he wanted to go to the battle instead, so the Prophet sallallahu alayhi wa sallam said that to him, showing him that he would be to him, by staying behind watching over women and children, like Haroon was to Musa when he left him behind as a deputy over his people, and it is an honor and that he wouldn’t be less than the ones who went to fight in battle.
and here is more on the hadith: