Sayyidah Aishah (may Allah be pleased with her) narrates from the Messenger of Allah (peace and blessings be upon him): "Whoever vows to obey Allah, let him obey Him, and whoever vows to disobey Him, let him not do so."
Imam al-Shafi'i (may Allah have mercy on him) says: The polytheists captured a woman of the Ansar and seized a she-camel of the Prophet (peace and blessings be upon him). The Ansari woman escaped on the she-camel of the Prophet (peace and blessings be upon him), and that woman had vowed to slaughter that she-camel of the Prophet (peace and blessings be upon him). When the Prophet (peace and blessings be upon him) came to know of it, he said: "There is no vow in disobedience, nor in what the son of Adam does not own."
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الجزية / 18852
Imam al-Shafi'i (may Allah have mercy on him) says that the Messenger of Allah (peace and blessings be upon him) said: "Whoever swears an oath to do something and then considers another thing better than it, let him do the better thing and pay the expiation for his oath."
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الجزية / 18853
Sayyiduna Abu Hurayrah (may Allah be pleased with him) says that the Messenger of Allah (peace and blessings be upon him) said: "Whoever swears an oath to do something and then considers another thing better than it, let him do the good thing and give the expiation for his oath."
Imam al-Shafi'i (may Allah have mercy on him) says: Obedience to Allah lies in this: when the other thing is better, do it and pay the expiation for the oath. From this it is known that every vow, and every covenant of a Muslim or of a polytheist, is to be fulfilled if it is permissible; a covenant involving disobedience to Allah is not to be fulfilled.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الجزية / 18854