All perfect praise be to Allaah, the Lord of the worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad, sallallaahu ‘alayhi wa sallam, is His Slave and Messenger.
It is impermissible for a man to imagine having sexual intercourse with a woman who is unlawful for him while having sexual intercourse with his wife. However, it is permissible to imagine having sexual intercourse with the second wife. Concerning your question about the accountability of an act after repenting of it; he will not be held accountable, for repentance eradicates any sin that precedes it. Imagining improbable fantasies is nonsense and a waste of time. It might lead the person to end up in compulsive obsession and committing what is unlawful. So, we advise you to avoid this act.
Allaah Knows best.