The great eighth century scholar Imaam Ibn al-Qayyim (died 752H, may Allaah have mercy upon him) said:
“The Prophet (may Allaah have mercy upon him) legislated for this nation the obligation of rejecting the evil so that by its rejection, the goodness that Allaah and His Messenger love is obtained. And when rejecting evil leads to what is more evil and more hated by Allaah and His Messenger then it is not allowed to reject it – even if Allaah hates the evil and detests those who perform it. And this is like censuring [the transgressions] of the kings and the ones in authority by coming out to fight against them for verily that is the basis and foundation of every evil and every tribulation till the end of time.
And the Companions asked permission from Allaah’s Messenger to kill the leaders who delay the prayer from its correct time saying, ‘Shall we not kill them?’
He replied, ‘No, so long as they establish the prayer.’
And he also said, ‘Whoever sees something from his Ruler that he dislikes, then let him be patient and let him not remove his hand from the Ruler’s obedience.’
And whoever reflects upon the greatest and smallest trials that have befallen Islaam, then he will see that that they are due to the negligence and wastage of this principle and the lack of patience when witnessing evil. So one seeks to bring about an end to evil and as a result of this, instead a greater evil is brought about. And the Messenger saw the greatest of evils in Mecca and yet he was not able to change them.
In fact even when Allaah opened up Makkah for the Muslims and it became a land of Islaam, he was resolved to changing the Kaʿbah and returning it to the foundations that Ibraaheem had built it upon, but even though he had the capacity to do that, he was prevented from it by the fear that something greater would occur due to the lack of tolerance of the [tribe of] Quraysh, since they were new to Islaam and had recently left unbelief.
For this reason he did not grant permission for rebelling against the leaders with the use of one’s hand due to the greatness of what results afterwards on account of it.” 
 Ibn Qayyim al-Jawziyyah, Iʿlaam al-Muwaqqiʿeen ʿan Rabb il-ʿAalameem.