The day of Ashura was a day that Quraysh used to fast during the days of ignorance, and the Messenger of Allah ﷺ used to fast it then as well. When the Messenger of Allah ﷺ arrived in Medina, he fasted it and ordered others to fast it. When the fast of Ramadan was made obligatory, that became the obligation, and Ashura was left optional. Whoever wished could fast it, and whoever wished could leave it.
حدثنا عبد الله بن مسلمة عن مالك عن هشام بن عروة عن أبيه
كان يوم عاشوراء يوما تصومه قريش في الجاهلية وكان رسول الله ﷺ يصومه في الجاهلية فلما قدم رسول الله ﷺ المدينة صامه وأمر بصيامه فلما فرض رمضان كان هو الفريضة وترك عاشوراء فمن شاء صامه ومن شاء تركه
Bukhari narrated it in the Book of Fasting, Chapter on Fasting the Day of Ashura, hadith no. 2002, from Abdullah bin Maslama Qanabi, and Muslim in the Book of Fasting, Chapter on Fasting the Day of Ashura, hadith no. 1125, from the hadith of Hisham bin Urwa with the same wording. It is also found in the Muwatta (Yahya's version), 1/299.