Quraysh used to fast on the day of Ashura during the days of ignorance, and the Messenger of Allah ﷺ used to fast it as well. When he migrated to Medina, he fasted it and ordered others to fast it. Then, when the month of Ramadan was made obligatory, he said, "Whoever wishes may fast it, and whoever wishes may leave it."
حدثنا زهير بن حرب حدثنا جرير عن هشام بن عروة عن أبيه
كانت قريش تصوم عاشوراء في الجاهلية وكان رسول الله ﷺ يصومه فلما هاجر إلى المدينة صامه وأمر بصيامه فلما فرض شهر رمضان قال من شاء صامه ومن شاء تركه