The World Federation One Stop Fiqh

Ruling 1566

If someone forgets that he is fasting and has sexual intercourse, or if someone is forced to have sexual intercourse in a manner that is not of his free will, his fast does not become invalid. However, in the event that during sexual intercourse he remembers [that he is fasting], or he is no longer forced to have sexual intercourse, he must immediately stop having sexual intercourse; and if he does not stop, his fast is invalid.