´It was narrated from 'Abdur-Rahman bin Samurah that the Prophet said:` "If you swear an oath, then you see something better than it, then offer expiation for your oath, and do that which is better."
Related hadith on this topic
Explanation & Benefits
Shaykh Umar Farooq Saeedi
Benefits and Issues:
If someone has taken an oath, but there is a Shari‘ah-based or moral benefit in acting contrary to it, then one should act upon the better course.
And the expiation (kafarah) for the oath should be given.
And there is flexibility in this matter: one may give the expiation before or after (breaking the oath).
Source: Sunan Abu Dawood – Commentary by Shaykh Umar Farooq Saeedi, Page: 3277