Ezra Stiles was a Congregationalist minister in Newport, Rhode Island in the late 18th century. He was a frequent visitor to the Newport Synagogue and there met Rabbi Raphael Hayyim Issac Carregal, a meshulach [fund raiser] from Hebron. In his diary, Stiles relates a question he asked Rabbi Carregal that stumped the good rabbi. After the rabbi agreed that marriage partners would be reunited in the resurrection, Stiles asked whether a woman was married to more than one man, to whom would she be reunited in the Resurrection? Rabbi Carregal (whose name is misspelled at that point in the diary, but spelled correctly elsewhere) replied that there are several opinions, but he did not know the answer. What opinions was he referring to?
Rav Pe'alim 2 - Sod Yesharim 2 says that she will return to her first husband since before Techiyas Hameisim the Neshama returns to the Neshama of the first spouse therefore it will remain so after Techiyas Hameisim. He further says that the (Guf) body that will get up for Techiyas Hameisim is a new Guf and the previous connection with the second husband will be broken.
Sefer Anaf Yosef - Sanhedrin beginning Perek Chelek says that the death of the first husband is similar to a divorce and the wife will remain with the second husband after Techiyas Hameisim.
R Shlomo Aviner answers this question basing himself on the Zohar
Regarding a Jewish servant, the verse says, "If he arrives by himself, he leaves by himself; if he is the husband of a woman, his wife leaves with him" (Shemot 21:3). This means that he enters the Resurrection of the Dead with his wife – his first wife.
There are commentators who explain that the meaning of the Zohar is that she will return to her true spouse, i.e. the most successful marriage (see note in Piskei Teshuvah). Thus, she will return to the marriage which was filled with the most love, fraternity, peace, and friendship.
R Yechiel Michel Tucazinsky in his Gesher Hachaim (section 3, chapter 8) asks to whom a woman married to two men (in succession) will return? He writes that the Zohar (Bereshit) answers she will return to her former husband.
R Tucazinsky quotes himself (section 1, 6:3) that this only applies where she had not born children to either husband, or else had children from both, but not if she had children from the second and not from the first. Other conditions affect this as well.