Short answer
The Qur'an commanded the marriage, to end an old Arab custom. Zaynab bint Jahsh was the Prophet's (ﷺ) own cousin. He had known her all her life. He himself had arranged her marriage to Zayd, his freed slave and adopted son. The marriage failed, and Zayd divorced her. In Arabia an adopted son counted as a son by blood, so no man could marry his adopted son's former wife. The Qur'an ended that custom. It told the Prophet (ﷺ) to marry Zaynab, so that believers would never face that difficulty again. He dreaded what people would say. The verse even corrects him for fearing people. Aisha, his wife, said that if he had ever hidden a verse, it would have been this one. So Islam teaches that the marriage was God's (﷾) command, and that he delivered it as he received it.
Full explanation
Who Zaynab and Zayd were
Zaynab bint Jahsh was the daughter of the Prophet's (ﷺ) aunt, so he had known her since she was a child. Zayd ibn Haritha was his freed slave, whom he had adopted as a son. It was the Prophet (ﷺ) who asked for Zaynab's hand on Zayd's behalf. The classical commentators (scholars who explained the Qur'an) report that she was at first unwilling. They say she agreed after the verse on obeying God (﷾) and His Messenger was revealed. The marriage lasted about a year before it broke down.
Ibn Kathir explains that Zaynab bint Jahsh was the daughter of the Prophet's (ﷺ) aunt Umaymah bint Abd al-Muttalib. The Prophet himself asked for her in marriage on behalf of his freed slave Zayd ibn Haritha. The marriage lasted about a year and then broke down, and Zayd came to the Prophet to complain. Ibn Kathir holds that what the Prophet hid was that God had told him Zaynab would be his wife, and he declines to repeat other reports on the verse because they are not sound.
“It is not fitting for a Believer, man or woman, when a matter has been decided by Allah and His Messenger to have any option about their decision: if any one disobeys Allah and His Messenger, he is indeed on a clearly wrong Path.”
The custom of adoption in Arabia
In Arabia an adopted son took his adoptive father's name and counted as his son in every way. The Companions, the Prophet's (ﷺ) followers, called Zayd, his adopted son, "Zayd son of Muhammad". The Qur'an ended this. It says that adopted sons are not sons by blood. It tells believers to call them by their own fathers' names. It also says that Muhammad (ﷺ) is not the father of any of their men.
Abdullah ibn Umar says that they used to call Zayd ibn Haritha, the Prophet's (ﷺ) freed slave, "Zayd son of Muhammad" until the verse was revealed telling them to call adopted sons by the names of their own fathers.
“Allah has not made for any man two hearts in his (one) body: nor has He made your wives whom ye divorce by Zihar your mothers: nor has He made your adopted sons your sons. Such is (only) your (manner of) speech by your mouths. But Allah tells (you) the Truth, and He shows the (right) Way.”
“Call them by (the names of) their fathers: that is juster in the sight of Allah. But if ye know not their father's (names, call them) your Brothers in faith, or your maulas. But there is no blame on you if ye make a mistake therein: (what counts is) the intention of your hearts: and Allah is Oft-Returning, Most Merciful.”
“Muhammad is not the father of any of your men, but (he is) the Messenger of Allah, and the Seal of the Prophets: and Allah has full knowledge of all things.”
The verse that commanded the marriage
When Zayd complained about his marriage, the Prophet (ﷺ) told him to keep his wife and fear God (﷾). Zayd later divorced her. The Qur'an then says that God (﷾) joined Zaynab to the Prophet (ﷺ) in marriage. It gives the reason in the same verse: so that believers would never again be barred from marrying the former wives of their adopted sons. The next verse adds that there is no blame on the Prophet (ﷺ) for doing what God (﷾) made his duty.
“Behold! Thou didst say to one who had received the grace of Allah and thy favour: "Retain thou (in wedlock) thy wife, and fear Allah." But thou didst hide in thy heart that which Allah was about to make manifest: thou didst fear the people, but it is more fitting that thou shouldst fear Allah. Then when Zaid had dissolved (his marriage) with her, with the necessary (formality), We joined her in marriage to thee: in order that (in future) there may be no difficulty to the Believers in (the matter of) marriage with the wives of their adopted sons, when the latter have dissolved with the necessary (formality) (their marriage) with them. And Allah's command must be fulfilled.”
“There can be no difficulty to the Prophet in what Allah has indicated to him as a duty. It was the practice (approved) of Allah amongst those of old that have passed away. And the command of Allah is a decree determined.”
Anas reports that Zayd ibn Haritha came to the Prophet (ﷺ) complaining about his wife, and the Prophet kept telling him to fear Allah and keep her. Aisha said that if the Prophet had hidden anything of the revelation, he would have hidden this verse. Zaynab used to tell the Prophet's other wives that their families had given them in marriage, but Allah had given her in marriage from above the seven heavens. Thabit adds that 33:37 was revealed about Zaynab and Zayd.
A verse he would have hidden if he could
The verse corrects the Prophet (ﷺ) for fearing what people would say. Aisha, his wife, drew the lesson. She said that if he had ever hidden anything revealed to him, he would have hidden this verse. He recited it anyway. Zaynab herself used to tell the other wives that their families had married them off, but God (﷾) had married her from above the seven heavens.
Aisha said that if Muhammad (ﷺ) had hidden anything that was revealed to him, he would have hidden the verse telling him that he had said to Zayd "keep your wife and fear Allah", while he hid in himself what Allah would reveal and feared the people, though Allah had more right to be feared.
Anas reports that Zayd ibn Haritha came to the Prophet (ﷺ) complaining about his wife, and the Prophet kept telling him to fear Allah and keep her. Aisha said that if the Prophet had hidden anything of the revelation, he would have hidden this verse. Zaynab used to tell the Prophet's other wives that their families had given them in marriage, but Allah had given her in marriage from above the seven heavens. Thabit adds that 33:37 was revealed about Zaynab and Zayd.
“Behold! Thou didst say to one who had received the grace of Allah and thy favour: "Retain thou (in wedlock) thy wife, and fear Allah." But thou didst hide in thy heart that which Allah was about to make manifest: thou didst fear the people, but it is more fitting that thou shouldst fear Allah. Then when Zaid had dissolved (his marriage) with her, with the necessary (formality), We joined her in marriage to thee: in order that (in future) there may be no difficulty to the Believers in (the matter of) marriage with the wives of their adopted sons, when the latter have dissolved with the necessary (formality) (their marriage) with them. And Allah's command must be fulfilled.”
What critics say, and the answer
Qur'an 4:23 — Surat al-Nisa (The Women), verse 23
“Prohibited to you (For marriage) are:- Your mothers, daughters, sisters; father's sisters, Mother's sisters; brother's daughters, sister's daughters; foster-mothers (Who gave you suck), foster-sisters; your wives' mothers; your step-daughters under your guardianship, born of your wives to whom ye have gone in,- no prohibition if ye have not gone in;- (Those who have been) wives of your sons proceeding from your loins; and two sisters in wedlock at one and the same time, except for what is past; for Allah is Oft-forgiving, Most Merciful;-”
Cited for
Critics say the Prophet (ﷺ) married his own daughter-in-law, which no decent man would do. They add that he simply redefined "son" when it suited him.
The response
The Qur'an does forbid marrying "wives of your sons proceeding from your loins". That means sons by blood. Zayd was an adopted son. The Qur'an says adopted sons are not your sons, and Muhammad (ﷺ) is not the father of any of your men. So Zaynab was never the wife of his own son. Arabs treated an adopted son as a real son, and the Qur'an ended that custom. It named this marriage as the way to end it, so that believers would never again be barred from such marriages. Verse 33:37 also shows that the Prophet (ﷺ) dreaded what people would say. That is not how a man acts who is changing the rules for himself.
Where it lands — Zayd was not his son by blood, and the marriage was the Qur'an's way of ending the custom that said he was.
Qur'an 33:37 — Surat al-Ahzab (The Clans), verse 37
“Behold! Thou didst say to one who had received the grace of Allah and thy favour: "Retain thou (in wedlock) thy wife, and fear Allah." But thou didst hide in thy heart that which Allah was about to make manifest: thou didst fear the people, but it is more fitting that thou shouldst fear Allah. Then when Zaid had dissolved (his marriage) with her, with the necessary (formality), We joined her in marriage to thee: in order that (in future) there may be no difficulty to the Believers in (the matter of) marriage with the wives of their adopted sons, when the latter have dissolved with the necessary (formality) (their marriage) with them. And Allah's command must be fulfilled.”
Cited for
Critics read "thou didst hide in thy heart" as a hidden desire for Zaynab. They rely on stories, recorded in some early histories and commentaries, that the Prophet (ﷺ) saw her and was struck by her beauty.
The response
The verse itself names what was hidden: "that which Allah was about to make manifest". What God (﷾) made manifest was the marriage, not a feeling. Ibn Kathir, one of the best-known commentators on the Qur'an, explains that God (﷾) had told the Prophet (ﷺ) Zaynab would be his wife. Ibn Kathir refuses to repeat the other stories because they are not sound. Zaynab was also his cousin. He had known her all her life and had chosen her for Zayd himself. If he had wanted her, he could have married her before she ever married Zayd.
Where it lands — The verse says the hidden thing was what God (﷾) would reveal, and the stories behind the critics' reading are not sound.
Perspectives
The Islamic perspective
God (﷾) commanded the marriage to abolish the custom that made an adopted son a son by blood. The Prophet (ﷺ) obeyed a command he dreaded, and he recited the verse that corrected him. That is the conduct of a messenger delivering what he was given.
The Qur'an states that God (﷾) joined Zaynab to the Prophet (ﷺ) in marriage. The reason given is that believers would face no difficulty in marrying the former wives of their adopted sons.
The Qur'an abolished the Arab custom of treating an adopted son as a son by blood.
Zaynab was the Prophet's (ﷺ) cousin, and he himself had arranged her marriage to Zayd.
Aisha, his wife, said that if the Prophet (ﷺ) had hidden any verse, he would have hidden this one.
One verse corrects the Prophet (ﷺ) for fearing people. It shows he delivered the revelation as he received it, even when it was hard.
The marriage was a command from God (﷾), and obeying it was the Prophet's (ﷺ) duty.