Imam al-Shafi'i (may Allah have mercy on him) said: "So whenever he is able to leave it (the abode of war), he should leave, because his oath is the oath of one under compulsion."
He (further) said: "And perhaps it is not permissible for him to remain with them when he is able to separate from them."
Hadith Referenceالسنن الكبرى للبيهقي / كتاب السير / Q18419