Praise be to Allah.
The ‘iddah of a woman if she is divorced before consummation of the marriage
If her first husband divorced her before consummating the marriage with her, then she did not have to observe ‘iddah and her second marriage is valid, because Allah, may He be exalted, says (interpretation of the meaning): “O You who have believed, when you marry believing women and then divorce them before you have touched them, then there is not for you any waiting period to count concerning them. So provide for them and give them a gracious release” [al-Ahzaab 33:49].
The iddah of a woman if she is divorced after consummation of the marriage
But if the divorce took place after her first husband consummated the marriage with her, then what she should have done was to observe an ‘iddah of three menstrual cycles, after which she could get married if she wished. Allah, may He be exalted, says (interpretation of the meaning): “Divorced women remain in waiting for three menstrual cycles” [al-Baqarah 2:228].
The scholars differed as to what is meant by quroo’ (translated here as “menstrual cycles”) – does it refer to when she becomes pure [the last day of her period] or to when the menses begins [the first day of her period]? The more correct view is that it refers to when the menses begins. This is the view of Abu Haneefah and Ahmad. al-Mughni (11/199).
So if she got married before her ‘iddah ended – as mentioned in the question – then the second marriage is invalid according to scholarly consensus. She must leave her second husband immediately, because he is not a husband for her, and she must complete her ‘iddah from the first husband, then observe ‘iddah from the second husband, then she may marry whomever she wishes.
Ibn Qudaamah (may Allah have mercy on him) said: It is not permissible for a woman who is observing ‘iddah to get married during her ‘iddah according to scholarly consensus, no matter what type of ‘iddah it is, because Allah, may He be exalted, says (interpretation of the meaning): “And do not determine to undertake a marriage contract until the decreed period reaches its end” [al-Baqarah 2:235]. … If she does get married, then the marriage is invalid. End quote from al-Mughni (11/237).
He also said: Once this is established, he must separate from her, and if he does not do that, then they must be separated. If he leaves or they are separated, she must complete the first ‘iddah, because [the first husband’s] rights come first, and ‘iddah from him must be observed if he had intercourse with her in the context of a valid marriage.
Once she has completed the first ‘iddah, she must observe ‘iddah for the second marriage.
The two ‘iddahs cannot be observed concurrently, because they are from two different men. This is the view of ash-Shaafa‘i.
Then he narrated this view from ‘Umar ibn al-Khattaab and ‘Ali ibn Abi Taalib (may Allah be pleased with them), then he said:
This is the view of two of the caliphs, and it is not known that any of the Sahaabah disagreed with them. Moreover, these are two separate rights for two human beings, so they should not be done concurrently. End quote from al-Mughni (11/239).
If the second husband is the one who will marry her [after she has observed both ‘iddahs], then there is a difference of opinion among the scholars: Does she have to observe ‘iddah for him after completing the first ‘iddah or not?
The correct view is that she does not have to do that, so she should complete the ‘iddah for the first husband, then she may marry the second husband.
Ibn Qudaamah (may Allah have mercy on him) said: ash-Shaafa‘i said in his later view: He may marry her after the ‘iddah for the first husband ends, and there is nothing wrong with him marrying her during the ‘iddah that she is observing for him [i.e., the second husband], because ‘iddah is only prescribed to preserve lineage and prevent the water [semen] from mixing, and in this case any offspring will be his, so it is like the case if he divorced her by means of khula‘ then remarried her during her ‘iddah. This is good and is in accordance with common sense… End quote from al-Mughni (8/100).
Shaykh Ibn ‘Uthaymeen (may Allah have mercy on him) said:
In principle, what is more likely to be correct is that it becomes permissible for him to marry her after the end of the first ‘iddah, especially if he has repented to Allah, may He be glorified and exalted, because the ‘iddah is for him. End quote from ash-Sharh al-Mumti‘ (13/383).
That must be done in the presence of her guardian (wali) and two witnesses, and with a new mahr.
Summary of the answer:
She must leave the second husband immediately and observe ‘iddah for the first one, then when that ‘iddah ends, she may marry the second husband if she wishes. That must be done in the presence of her guardian (wali) and two witnesses, and with a new mahr.
If she and her family did that without knowing that ‘iddah is obligatory, she does not have to do anything apart from what we have mentioned of the ‘iddah that is obligatory for her. And you should seek forgiveness from Allah for failing to ask people of knowledge before entering into any shar‘i contract. Then she does not have to offer any expiation or do anything else.
And Allah knows best.