All perfect praise be to Allah, The Lord of the Worlds. I testify that there is none worthy of worship except Allah, and that Muhammad is His slave and Messenger.
It is forbidden to marry if one knows that such a marriage contract is invalid. Then, if one has sex after such a marriage, this will be a form of Zina (fornication or adultery). So, one has to separate oneself from such a marriage and repent faithfully. After that, if he wants to have a valid marriage, then there is no problem provided that the woman observes one period of menstruation and then becomes pure in order to make sure that she is not pregnant, since this is due to invalid marriage.
As for divorce after an invalid marriage, then such a divorce (whether it is the first, second or even the third) constitutes nothing since it originally happened after an invalid marriage.
Allah knows best.