Praise be to Allaah.
There is no contradiction between these hadeeths. If a man marries a woman who has been divorced three times with the intention of making her permissible for the first husband (tahleel marriage), this marriage is haraam and is that which the Messenger of Allah (blessings and peace of Allah be upon him) cursed the one who does it.
As for the hadeeth about the wife of Rifaaah, it does not say that Abd al-Rahmaan ibn al-Zubayr married her with the intention of tahleel. Rather the reports of the hadeeth indicate that he married her and wanted to keep her, and he did not divorce her just because she asked for a divorce. Rather she wanted to go back to her first husband, but the Prophet (blessings and peace of Allah be upon him) explained to her that that would not be permissible for her until the second husband consummated the marriage with her; she had said that he had not consummated the marriage with her.
There follow some of the versions of the hadeeth about the wife of Rifaaah.
It was narrated by al-Bukhaari (2639) and Muslim (1433) from Aa'ishah (may Allah be pleased with her) that: The wife of Rifaaah al-Qurazi came to the Prophet (blessings and peace of Allah be upon him) and said: I was married to Rifaaah, then he divorced me and made the divorce irrevocable. Then I married Abd al-Rahmaan ibn al-Zubayr. He said: Do you want to go back to Rifaaah? No, not until you taste his (Abd al-Rahmaan's) sweetness and he tastes your sweetness.
Muslim (1433) narrated that Aa'ishah (may Allah be pleased with her) said: A man divorced his wife three times, then another man married her and divorced her before consummating the marriage with her. Her first husband wanted to remarry her, and the Prophet (blessings and peace of Allah be upon him) was asked about that. He said: No, not until the second husband tastes of her sweetness what the first one tasted.
So it does not say in the hadeeth that Abd al-Rahmaan married her with the intention of tahleel (making her permissible for her first husband). Rather she is the one who wanted to go back to her first husband, and the fact that this intention was present on her part does not make the marriage a tahleel marriage, because the power of divorce was not in her hand.
Shaykh al-Islam Ibn Taymiyah (may Allah have mercy on him) said:
Because the Prophet (blessings and peace of Allah be upon him) permitted her to go back to her first husband if the second husband had intercourse with her, after it became clear to him that she wanted to go back to the first husband, and it made no difference whether this desire arose after the marriage contract was done or was present before that, this indicates that it was permissible for her to go back to (the first husband) in either case. Usually if a woman is comfortable with her husband then he divorces her, she may still feel something for him in many cases; women usually dislike divorce and would like to go back to the first husband more than they would like to live with someone elseâ€¦ End quote.
Al-Fataawa al-Kubra, 6/301
Ibn Abd al-Barr (may Allah have mercy on him) said:
In the words of the Prophet (blessings and peace of Allah be upon him) to the wife of Rifaaah, Do you want to go back to Rifaaah? There is an indication that the woman's desire to go back to her (first) husband does not affect the one who has done the marriage contract with her, and that does not come under the same heading as tahleel, in the case of which the one who does it deserves to be cursed. End quote.
Ibn al-Qayyim (may Allah have mercy on him) said:
The intention of the wife or her guardian does not have any effect; rather what counts is the intention of the second husband. If he intends to make it permissible for her to go back to her first husband (tahleel), then he is muhallil and deserves to be cursed, as does the husband who divorced her, if she goes back to him by means of this invalid marriage. But if neither the second husband nor the first husband was aware of what was in the mind of the woman or her guardian of the intention of tahleel, that does not affect the marriage contract at all. The Prophet (blessings and peace of Allah be upon him) was aware that the wife of Rifaaah wanted to go back to him and he did not make that the reason to prevent her going back to him; rather what prevented her going back to him was the fact that the second husband had not had intercourse with her, so he said, not until you taste his sweetness and he tastes your sweetness. End quote.
Ilaam al-Muwaqqieen, 4/45-46
And Allah knows best.