Prophet Muhammad was worried about people rebelling against him if he announced Imam Ali as his successor, so he delayed following the message to formalize his succesorship as long as he was allowed to.
The wisdom of this showed by how during the hajj. Some companions of the Prophet had suspected the Prophet would announce Imam Ali as his successor at hajj and whenever the prophet would give a sermon that veered towards this topic, they would become agitative and make noise in order to derail the announcement.
After the hajj, the Muslims started travelling back towars their home towns, with the Yemenis going south, and the Meccans remaining behind in Mecca, while the prophet and others went north to Medina. At this time Gabriel once again conveyed Allah’s command to the Prophet to announce his successor and this time also promised His protection. Perphaps after the groups had split the munafiqeen were in too small a number to cause any trouble, and Prophet Muhammad announced Imam Ali as his successor.
Podcast version: podcast.lifeofprophetmuhammad.com