Source
Taken from: Fatāwā Amunpuri by Shaykh Ghulām Muṣṭafā Ẓahīr AmunpuriQuestion
If an oath is broken because the act for which the oath was taken was unlawful, is expiation (kaffārah) still required?Answer
Regardless of the reason for breaking an oath, expiation (kaffārah) becomes obligatory.Evidence from the Sunnah
❀ Sayyidunā Abū Mūsā al-Ashʿarī رضي الله عنه narrated that the Messenger of Allah ﷺ said:لا أحلف على يمين فأرى غيرها خيرا منها إلا أتيت الذى هو خير وتحللتها.
“I do not take an oath over something and then see that something else is better than it, except that I do what is better and release myself from the oath (by offering its expiation).”
Reference: Ṣaḥīḥ al-Bukhārī: 3133
Reference: Ṣaḥīḥ Muslim: 1649