Question: If a man says, “I am a Jew” or “I am a Christian if I do such-and-such,” is he judged thereby to have disbelieved and his wife to have been divorced, even if he does not do the act on account of which he swore? Or does he not disbelieve unless that act is actually realized?
Answer – and Allah is the One who grants success: It is not appropriate to swear by such expressions, whether he fulfills his oath or not, and whether he is truthful or lying, except if necessity forces him and he is truthful in his oath. They have used as evidence for the permissibility of that His saying, Exalted is He: “Say, ˹O Prophet,˺ ‘If the Most Compassionate ˹really˺ had offspring, I would be the first worshipper.’” [Az-Zukhruf:81]. He is not judged to be a disbeliever, nor his marriage to be annulled, if he does not do (the act), because he has suspended disbelief upon the act.
If he does what he swore upon, then his wife does not become separated from him so long as he persists in outwardly manifesting Islam; for it has not been transmitted from the Prophet (May Allah bless him and his family and grant them peace) that he ruled that the marriages of the hypocrites were annulled from their wives, although they uttered the word of disbelief and intended what they did not attain, and Allah, Exalted is He, has described them with the attributes of the disbelievers in many verses.
This being so, it appears that what you have asked about is lighter than what Allah has mentioned concerning the hypocrites, and Allah knows best.
Source: Min Thimār al-ʿIlm wa al-Ḥikmah vol.2