All perfect praise be to Allah, the Lord of the Worlds. I testify that there is none worthy of worship except Allah, and that Muhammad, sallallaahu ‘alayhi wa sallam, is His Slave and Messenger.
The answer of this question was mentioned by Al-Haafith Ibn Hajar as he said,
Ahmad narrated this Marfoo‘ Hadeeth (i.e., directly attributed to the Prophet ) on the authority of Ibn ‘Abbaas: 'Fast the tenth of Muharram and be different from the Jews by fasting one day before it or after it.' This was at the end because the Prophet, sallallaahu ‘alayhi wa sallam, used to do the same as the People of the Book in matters where he was not ordered to do otherwise, especially when this would be contradicting the idolaters. However, when Makkah was conquered and Islam became widespread, the Prophet, sallallaahu ‘alayhi wa sallam, liked to differ from the People of the Book, like what was narrated in As-Saheeh. The Prophet, sallallaahu ‘alayhi wa sallam, did the same like what the People of the Book did initially, then later said: 'We are worthier of Moosa than them.' Then he liked to be different from them and ordered us to fast one day before it or after it.
Thus, the Prophet, sallallaahu ‘alayhi wa sallam, intended to fast the ninth of Muharram in order to be different from the Jews when Islam was widespread and its followers increased in number, but before this he used to do the same like what the People of the Book did in matters that did not include a Commandment or prohibition from Allah, The Almighty.
Allah knows best.