Ali remained behind the Prophet (ﷺ) during the battle of Khaibar as he way
suffering from some eye trouble but then he said, "How should I stay
behind Allah's Messenger (ﷺ)?" So, he set out till he joined the Prophet. On
the eve of the day of the conquest of Khaibar, Allah's Messenger (ﷺ) said,
"(No doubt) I will give the flag or, tomorrow, a man whom Allah and
His Apostle love or who loves Allah and His apostle will take the
flag. Allah will bestow victory upon him." Suddenly 'Ali joined us
though we were not expecting him. The people said, "Here is 'Ali. "So,
Allah's Messenger (ﷺ) gave the flag to him and Allah bestowed victory upon
him.
Sahih al-Bukhari Book 56, Hadith 184