The wisdom behind the calamities that befell the Prophets
Question

We know that calamities may be because of sins and that they expiate sins, but what is the wisdom behind the calamities that befell the Prophets?.
Praise be to Allah.Firstly: 
One of the reasons for calamities is sins, but that is not the only reason. Allaah may test some of His slaves who did not sin, so that they may attain the reward of the patient, and thus be raised in status. Allaah may also test some children, who have no sin. In order to learn more about the wisdom behind calamities, please see question no. 35914. 
Secondly: 
The most severely tested of the people are the Prophets. 
Al-Tirmidhi (2398) narrated that Sa’d ibn Abi Waqqaas (may Allaah be pleased with him) said: I said: “O Messenger of Allaah, which of the people are most sorely tested?” He said: “The Prophets, then the next best and the next best. A man will be tested in accordance with his level of religious commitment. If his religious commitment is strong, he will be tested more severely, and if his religious commitment is weak, he will be tested in accordance with his religious commitment. Calamity will keep befalling a person until he walks on the earth with no sin on him.” Classed assaheeh by al-Albaani in al-Silsilah al-Saheehah, 143. 
In His Book, Allaah has mentioned different kinds of calamity that befell the Prophets. 
Allaah says: 
“And indeed, We gave Moosa (Moses) the Book and followed him up with a succession of Messengers. And We gave ‘Isa (Jesus), the son of Maryam (Mary), clear signs and supported him with Rooh-ul-Qudus [Jibreel (Gabriel)]. Is it that whenever there came to you a Messenger with what you yourselves desired not, you grew arrogant? Some you disbelieved and some you killed”
[al-Baqarah 2:87]
“And when it is said to them (the Jews), ‘Believe in what Allaah has sent down,’ they say, ‘We believe in what was sent down to us.’ And they disbelieve in that which came after it, while it is the truth confirming what is with them. Say (O Muhammad to them): ‘Why then have you killed the Prophets of Allaah aforetime, if you indeed have been believers?’”
[al-Baqarah 2:91]
“Then if they reject you (O Muhammad), so were Messengers rejected before you, who came with Al‑Baiyyinaat (clear signs, proofs, evidences) and the Scripture and the Book of Enlightenment”
[Aal ‘Imraan 3:184]
“And (remember) when Moosa (Moses) said to his people: ‘O my people! Why do you annoy me while you know certainly that I am the Messenger of Allaah to you?’ So when they turned away (from the path of Allaah), Allaah turned their hearts away (from the Right Path). And Allaah guides not the people who are Faasiqoon (rebellious, disobedient to Allaah)”
[al-Saff 61:5]
“And among them are men who annoy the Prophet (Muhammad) and say: ‘He is (lending his) ear (to every news).’ Say: ‘He listens to what is best for you; he believes in Allaah; has faith in the believers; and is a mercy to those of you who believe.’ But those who annoy Allaah’s Messenger (Muhammad) will have a painful torment”
[al-Tawbah 9:61]
Ibraaheem (peace be upon him) was tested with the enmity of his father and his people, and by being thrown into the fire. 
Allaah says (interpretation of the meaning): 
“They said: ‘Burn him and help your aalihah (gods), if you will be doing.’
69. We (Allaah) said: ‘O fire! Be you coolness and safety for Ibraaheem (Abraham)!’
70. And they wanted to harm him, but We made them the worst losers”
[al-Anbiya’ 21:68-70]
And he was tested with the command to sacrifice his son Isma’eel 
Allaah says (interpretation of the meaning): 
“And, when he (his son) was old enough to walk with him, he said: ‘O my son! I have seen in a dream that I am slaughtering you (offering you in sacrifice to Allaah). So look what you think!’ He said: ‘O my father! Do that which you are commanded, In sha’ Allaah (if Allaah wills), you shall find me of As‑Saabiroon (the patient).’
103. Then, when they had both submitted themselves (to the Will of Allaah), and he had laid him prostrate on his forehead (or on the side of his forehead for slaughtering);
104. We called out to him: ‘O Abraham!
105. You have fulfilled the dream’  Verily, thus do We reward the Muhsinoon (good‑doers. See 2:112).
106. Verily, that indeed was a manifest trial.
107. And We ransomed him with a great sacrifice (i.e.— a ram)”
[al-Saaffaat 37:102-107]
Ibn al-Qayyim said in al-Fawaa’id (p. 42) 
The path is the path for which Adam exerted himself, and for which Nooh wept, and al-Khaleel was thrown into the fire, and Ismaa’eel was laid down to be sacrificed, and Yoosuf was sold for a low price and remained in prison for several years, and Zakariya was cut in two with a saw, and Yahya was slaughtered, and Ayyoob suffered severe illness, and Muhammad (peace and blessings of Allaah be upon him) suffered poverty and all sorts of trials and tests. End quote. 
Our Prophet (peace and blessings of Allaah be upon him) was told of the calamities that he would face from the first day of his Prophethood. 
Waraqah ibn Nawfal said: “Would that I were a young man, would that I would be alive when your people expel you.” The Messenger of Allaah (peace and blessings of Allaah be upon him) said: “Will they expel me?” He said: “Yes. No man has ever come with that which you have brought but he was faced with hostility. If I live to see that day, I will support you strongly…” Narrated by al-Bukhaari (4). 
Thirdly: 
With regard to the wisdom behind the calamities that befell the Prophets, Ibn al-Qayyim said in Badaa’i’ al-Fawaa’id (2/452): 
Just as Allaah protects the Prophets and takes care of them, so too He tests them as He wills with the kaafirs’ persecution of them. 
1-So that they may attain a level where they deserve His honour in full.
2-So that those who come after them of their nations and successors will be consoled if they are persecuted by the people; they will see what happened to the Messengers and Prophets, so they will be patient and content and will follow their example.
3-So that the kuffaar may get carried away in their sin and thus will deserve the punishment that is prepared for them in this world and in the Hereafter, so Allaah will destroy them because of their enmity and aggression, and the earth will be cleansed of them.
These are some of the reasons why Allaah tested His Prophets and Messengers with the persecution of their people. Great Wisdom is His and from Him come perfect blessings. There is no god but Him and no Lord besides Him. End quote. 
Ibn al-Qayyim said in Miftaah Dar al-Sa’aadah (1/299-301): 
If you ponder Allaah’s wisdom in that with which He tests His slaves and chosen ones, by means of which He directs them to achieve the highest goals and reach the highest positions, which they could not have achieved without these tests and trials… all these tests and trials are in fact a kind of honour, for while they appear to be trials and tests, in fact they are mercy and blessings. How many great blessings from Allaah are the direct consequences of tests and trials? 
Think about the story of our father Adam (peace and blessings of Allaah be upon him), and how his test ended with him being chosen and brought close to Allaah, and repenting and being guided and raised in status. 
Think about the story of our second father Nooh (peace and blessings of Allaah be upon him), and how his test and patience with his people all those centuries led to his victory, when the people of earth were drowned in answer to his prayer, and mankind after that were all descended from his offspring, and Allaah made him the fifth of five, namely the Messengers of strong will (cf. al-Ahqaaf 46:35), who are the best of the Messengers. And Allaah commanded His Messenger and Prophet Muhammad (peace and blessings of Allaah be upon him) to be patient like him, and praised him for his gratitude, saying (interpretation of the meaning): “Verily, he was a grateful slave” [al-Isra’ 17:3], and He described him as being perfect in patience and gratitude. 
And think about the story of our third father Ibraaheem (peace and blessings of Allaah be upon him), the imam of the monotheists and the Shaykh of the Prophets, the pillar of the world and the Close Friend of the Lord of the Worlds among the sons of Adam. Think about what his trials and patience and his offering himself to Allaah led to. Think how his offering himself to Allaah and supporting His religion led to Allaah taking him as a close friend (khaleel) for Himself…. And Allaah multiplied his descendants and blessed them and increased them until they filled the world, and He caused Prophethood and holy Books to be limited to his progeny thereafter, and He brought forth from them Muhammad (peace and blessings of Allaah be upon him) and commanded him to follow the path of his father Ibraaheem. 
Then think about the one who spoke with Allaah, Moosa (peace be upon him), and what his trials and tests from the day of his birth until the end of his life led to, until Allaah spoke to him directly and brought him close to Him,  He wrote to Torah for him with His hand and raised him up to the highest heavens, and He forgave him for what He may not forgive anyone else, for he threw the Tablets to the ground and they broke, and he seized the beard of the Prophet of Allaah Haroon and pulled him towards him, and he smacked the face of the Angel of Death and put out his eye, and he argued with his Lord on the night of the Isra’ concerning the Messenger of Allaah, but his Lord loved him in spite of all that, and none of that made his Lord get upset with him, or lowered his status before Him. Rather he is close to Allaah. Were it not for the great trials and calamities that he had already gone through for the sake of Allaah and the immense hardships that he had suffered with Pharaoh and his people then with the Children of Israel, and the harm they caused him and the patience with which he bore it, he could not have achieved all that. 
Think about the Messiah (peace and blessings of Allaah be upon him) and his patience in dealing with his people, his forbearance for the sake of Allaah and how much he had to put up with, until Allaah raised him up and cleansed him of those who disbelieved and wrought vengeance upon his enemies, scattering them throughout the earth and taking away their kingdom and their pride until the end of time. 
And when you come to the story of the Prophet (peace and blessings of Allaah be upon him) and think about his experience with his people and his patience for the sake of Allaah, how he put up with things that no other Prophet before him had had to bear, facing all kinds of situations, safety and fear, richness and poverty, security and stability in his own homeland then moving away and leaving it for the sake of Allaah, the killing of his loved ones and friends before his eyes, the kaafirs’ persecution of him in word and deed, using magic, lies and fabrications against him, but despite all that he was patient in obeying the command of Allaah and calling people to Allaah. No Prophet was persecuted in the way that he was persecuted, or went through what he went through for the sake of Allaah, and no Prophet was rewarded as he was rewarded, for Allaah raised high his fame (cf. al-Sharh 94:4), joined his name to His and made him the leader of all mankind; He made him the closest of creation to Him, the greatest in status before Him and the one whose intercession is always accepted. Thus these trials and calamities were in fact an honour for him, by means of which Allaah increased him in honour and virtue, and granted him the highest status. 
And this is the case with his heirs after him; each one will have his share of trials and tests, which will help him to attain perfection according to his following of the Prophet. 
And Allaah knows best.