The people of the pre-Islamic era used to fast on the day of Ashura, and the Messenger of Allah ﷺ and the Muslims fasted it before the fast of Ramadan was made obligatory. When Ramadan was made obligatory, the Messenger of Allah ﷺ said, "Ashura is one of the days of Allah the Exalted, so whoever wishes may fast it, and whoever wishes may leave it."
حدثنا ابن نمير أخبرنا عبيد الله عن نافع قال
أن أهل الجاهلية كانوا يصومون يوم عاشوراء وأن رسول الله ﷺ صامه والمسلمون قبل أن يفترض رمضان فلما افترض رمضان قال رسول الله ﷺ إن عاشوراء يوم من أيام الله تعالى فمن شاء صامه ومن شاء تركه