´It was narrated from 'Abdur-Rahman bin Samurah that the Messenger of Allah said:` "If any one of you swears an oath, then he sees something better than it, let him offer expiation for his oath, and look at what is better and do it."
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