A necessary aspect of any government or rule is that the ruler has to have supporters who fill some of his roles, needs and responsibilities. It is not possible for the overall leader to directly take care of all concerns. He cannot judge between the people in all of their disputes and he cannot fulfill all of their needs. This is something well known and admitted.
The question, then, is: What is the ruling concerning taking a government position for a ruler who is an evildoer, a wrongdoing oppressor or a disbeliever?
As for the ruler who is an evildoer, the scholars and judges of the Muslims, from the time of the early scholars and afterwards, continue to take judicial posts under those who are not acting righteously. If they were not to take such posts, the laws of the Shareeah would be voided in practice. 
As for the disbelieving ruler or one who is openly committing wrong and oppression, the scholars have differed concerning taking a post or job with someone of that nature. There are two opinions on this question. The first opinion says that it is allowed to take such a position as long as the deeds the person is performing in following that ruler are just and correct.
The second opinion states that it is not allowed to take any position from a blatantly oppressing wrongdoer. 
The proponents of the first opinion offer a number of proofs, including:
(1) Allah said in the words of Yoosuf,
"(Yoosuf) said, 'Set me over the store-houses of the land: I will indeed guard them, as one that knows (their importance)'" (Yoosuf 55).
Ibn Attiyah stated,
"Some of the interpreters stated that in this verse is [the indication of] permissibility for a virtuous person to work for an evil person, on the condition that he will be in charge of what he does and not be objected to. Hence, he will be able to reform and correct what he wills. However, if his deeds will be according to what the evildoer decides and wants, then it is not allowed for him to [take such a position]." 
Al-Zamakhshari  said,
"Qataadah said that this is evidence that it is allowed for a person to take a position from an unjust ruler. The early Muslims would fill the positions and responsibilities of judges for the oppressors. If a prophet or a scholar knows that there is no way to rule by the command of Allah or repel wrongdoing except by the establishment of a disbelieving or impious king, he may support him." 
(2) [Second, they invoke the issue of] taking into consideration or weighing the good and the evil of a deed. Al-Izz ibn Abdul Salaam said,
"If the disbelievers overtake a large country and the position of judge is given to one who can look after the needs of the Muslims masses, it seems apparent that he should fulfill that post in order to bring about general good and repel comprehensive evil. Given the mercy of the Lawgiver and His care for the needs of His servants, it is far-fetched to think that the general benefits would be given up and general evil would be allowed to prevail simply due to the capable person having to give up some aspect of the completeness of his character by not taking such a position. This is far-fetched indeed." 
Based on this principle, ibn Taimiyyah ruled that it is permissible to take a position of authority or a fief by one who is put in responsibility by rulers who have some wrong to them, with his intention that he will fulfill what is just.
Ibn Taimiyyah stated,
"All praise be to Allah. Yes, if he is striving for justice and removing of wrong to the best of his ability [he may take such a position]. His being in charge is better and more beneficial than the authority of others. His being in control over a fief is better than others being in charge... It is permissible for him to remain in the position of authority or in a fiefdom and there is sin upon him for that. In fact, his remaining in that position is better than him leaving it, unless he preoccupies himself with something better than it." 
Ibn Taimiyyah considered Yoosufs, the trustworthy, taking the position of treasurer for the king of Egypt to have been of this nature. He said,
"Yoosuf was not able to do whatever he wanted to do, which was what he saw as the religion of Allah, for the people would not respond to him. However, he was able to do what he could of justice and beneficence and having the ruler honor the believers from his family. He was not able to do that before. This all fell under the meaning of His words, 'So fear Allah as much as you can' (al-Taghaabun 16)." 
(3) The point to consider for the Shareeah ruling and for the sinfulness of the one taking the post is what he himself does and not what the ruler does. 
The evil in a deed of that nature comes from one of two aspects:
(a) the intention, (b) the deed.
As for the evil in the intention, it is where the person intends authority or wealth. As for the evil in the deed, it is where a forbidden deed is done or an obligatory deed is neglected.  Hence, the evilness of the ruler in himself is not a cause for evilness in the works of the one given a post or in a position of responsibility.
The proponents of the second opinion offer two points as evidence for their side. 
(1) Accepting a job from the wrongdoing oppressors is a form of showing loyalty and support for them.
(2) Also, in that act there is a type of attestation of their [that is, the rulers'] goodness by following their deeds.  They respond to the story of Yoosuf in a number of ways, including:
(a) The Pharaoh at the time of Yoosuf was pious. In fact, it is narrated from Mujaahid that he had embraced Islam. 
(b) Yoosuf would tend to the government lands and not to the Pharaoh's deeds. Hence, the responsibility for the Pharaoh's deeds would be removed from him. 
(c) The king would accept Yoosufs opinion and he would not object to anything Yoosuf opined. Hence, he was more the follower and Yoosuf the followed. 
Critique and Determining the Strongest View:
Allah knows best but the strongest opinion seems to be the first opinion. The reasons given by the proponents of the second opinion may be responded to in the following:
(1) Loyalty is something external to working under the authority of a disbelieving ruler. There is no necessary relationship between them. It is possible for someone to fulfill his work, which includes raising the word of Allah and fulfilling the truth, while not having love or loyalty for the ruler himself. Indeed, he may do those acts to circumvent the ruler and to guard against his evil. In that case, it falls under the words of Allah,
"Except by way of precaution" (ali-Imraan 28).
(2) This taking of a position does not entail any form of attestation or sanctioning of the ruler. Indeed, it is simply taking some role that the ruler either left or concerning which he is compromising and applying it in the proper Shareeah manner. Ibn al-Arabi stated while commenting upon Yoosuf's request to the king to be put over the storehouses of the land,
"He was not asking for a position of authority. He was asking him to leave it so it would be then transferred to his authority. If Allah had willed, He could have established his authority via fighting, death, overpowering, power and control. However, Allah applies His laws with respect to the prophets and the different nations according to what He has mentioned. For some of them, the prophets were dealt with through power, authority and taking control [such as between Moses and the Pharaoh]. For some of them, the prophets were dealt with through strategies and trials [such as in the case of Yoosuf]. This is indicated by Allah's words, 'Thus did We give established power to Joseph in the land, to take possession therein as when or where he pleased. We bestow of Our mercy on whom We please, and We suffer not to be lost the reward of those who do good' (Yoosuf 56)." 
Their replies to the story of Yoosuf and his requesting from the King to be put over the storehouses of the land can in turn be replied to by the following:
(1) They state that the Pharaoh at the time of Yoosuf was pious and Mujaahid even narrated that he had embraced Islam.
However, there is no Shareeah evidence for this claim. In fact, the texts of the Quran indicate otherwise.
Ibn Taimiyyah noted about the Pharaoh at the time of Yoosuf,
"He and his people were disbelievers. As Allah says [about them on the tongue of a man who lived during the time of Moses], 'And to you there came Joseph in times gone by, with clear signs, but you ceased not to doubt of the (mission) for which he had come...' (Ghaafir 34).
Allah also says, stating Yoosuf's words,
'O my two companions of the prison! (I ask you): Are many lords differing among themselves better, or Allah, the One Supreme and Irresistible? If not Him, you worship nothing but names which you have named, you and your fathers' (Yoosuf 39-40) ." 
It is understood that these verses indicate that the King was not of the same religion as Yoosuf. Even if we assume that he embraced Islam later, he was still a disbeliever when Yoosuftook the post.
(2) Their statement that he looked after the government lands not the actions [ofthe ruler] also has no evidence for it. The Quran makes clear that Yoosuf was established in the land. Allah says,
"Thus did We give established power to Joseph in the land, to take possession therein as when or where he pleased. We bestow of Our mercy on whom We please, and We suffer not to be lost the reward of those who do good" (Yoosuf 56).
The Quranic commentators state that the Pharaoh put him in charge of Egypt and he was in charge of all affairs. 
Even if we assume that Pharaoh only put him over the governmental lands, that actually falls within the actions of the ruler. It is well known that Pharaoh and his people, in their kufr, must have had customary ways and practices to take possession of wealth and spend it on the king's entourage, family, soldiers and citizens. No doubt those practices were not in accord with the practices of the prophets and their just ways. 
Therefore, one does not escape by this argument the question of working for a disbelieving ruler. Indeed, this is included as part of that act.
(3) They argue that the King would promulgate Yoosuf's views and would not object to them at all in any matter. Hence, Yoosuf was like the one being followed. There is also no evidence for this.
In fact, the clear meaning of the Quran contradicts it. Yoosuf was not able to take his brother except through tricky means. This shows that he did not have complete independence. Furthermore, the entire discussion is about the taking of a post and accepting a job from a disbeliever, regardless of how independent the opinion of the one taking the post would be.
This shows that the opinion that it is permissible to accept a job or post from a clearly oppressive ruler or a disbelieving ruler, as long as the work itself does not involve doing something forbidden.
Furthermore, ibn Taimiyyah notes that one must consider the benefit and harm of accepting such a post. If the benefit outweighs the harm it is permissible, even if the one taking the post is engaged in some act of wrongdoing, as long as his intention is to fulfill what is correct and to establish justice. 
By this presentation, it is clear that prohibiting the people from working in government posts is a form of extremism.  Some of the modern groups fell into this form of extremism.
Shukri Mustafa's group viewed engaging in any type of job in what they called the jaahili society was an act of worshiping the taaghoot (false gods), even if the work itself was of a permissible nature.
Maahir Bakri stated,
"Every work, permissible or forbidden, in this jaahili society, must, in the long run, flow to one end: the help and support of the foundation of this disbelieving society. Look at the extent of the sin the one who is pleased to live with the disbelievers and remain among their midst receives. He has taken it upon himself to work in the paltriest of jobs and the one least in value." 
After listing a number of acts that the people are involved in [in contemporary society], Shukri Mustafa stated,
"All of that... is but the authority of the taaghoot (false god), his jurisdiction and the sources of his goodhood. Those who enter into his system are nothing but his slaves and custodians of his pulpit. There is nothing among the things we mentioned-not even a piece of trash that is removed by the order of the municipality-in the land of the taaghoot except that it falls under his godhood." 
That view of theirs is built upon [their view] that the land is a land of kufr and the society is a jaahili society. Hence, those who live there are disbelievers, with the ruling class and the citizenry being the same in that matter.
All of these issues were discussed as part of this research.
Their falsehood has been explained. And what is built upon a false premise is also false.
1) Cf., al-Zamakhshari, Kashaaf, vol. 2, p. 263; ibn Hayyaan, al-Bahr al-Muheet, vol. 5, p. 319; al-Qaasimi, Mahaasin al-Taweel, vol. 9, p. 3559.
2) Cf., al-Maawardi, al-Ahkaam al-Sultaaniyyah, p. 75; al-Qurtubi, Al-Jaami Ii-Ahkaam al-Quraan, vol. 7, p. 215; al-Wanshareesi, al-Miyaar al-Marrib, vol. 10, p. 109
3) Al-Muharar wa al-Wajeez, vol. 8, pp. 5-6. Al-Qurtubi quoted from some scholars similar to what ibn Atiyyah quoted, except he said, "Some scholars say that this verse contains a permission for the righteous person to work for an evildoing person or a disbelieving ruler." Al-Jaami Ii-Ahkaam al-Quraan, vol. 7, p. 215.
4) He was Jaarullaah Mahmood ibn Umar ibn Muhammad al-Khawaarizmi al-Zamakhshari. He was a Quranic commentator. His commentary is known as al-Kashaaf. It is filled with the views of the Mutazilah. He was also a linguist, compiling a work entitled Asaas al-Balaaghah. He died in 538 A.H. Cf., Siyar Alaam al-Nubalaa, vol. 20, p. 153; al-Alaam, vol. 7, p. 178.
5) Al-Kashaaf, vol. 2, p. 263. Cf., Abu Hayaan, Al-Bahr al-Muheet, vol. 5, pp.
319-320; Abu al-Saood, lrshaad al-Aql ai-Saleem, vol. 3, p. 160; al-Suyooti, al-Ikleel fi Istinbaat al-Tanzeel, p. 132; al-Qaasimi, Mahaasin al-Taweel, vol. 9, p.3559.
6) Qawaaid al-Ahkaam, vol. 1, p. 75.
7) Ibn Taimiyyah, al-Fataawa, vol. 30, p. 368. Cf., Abu Hayyaan, al-Bahr al-Muheet, vol. 5, pp. 319-320.
8) Ibn Taimiyyah, al-Fataawa, vol. 20, p. 54.
9) Cf., al-Qurtubi, Al-Jaami li-Ahkaam al-Quraan, vol. 7, p. 215.
10) Cf., ibn Taimiyyah, al-Fataawa, vol. 20, p. 56.
11) [The author here does not discuss one of the strongest evidences they present. Some have stated that the actions of Yoosuf, his requesting the position and his working for the Pharaoh, are related to a Shareeah or law that existed before the Shareeah of the Prophet Muhammad (peace and blessings of Allah be upon him), which abrogated and superseded all previous Shareeahs. There is a well known and lengthy debate within Islamic legal theory as to whether the Shareeahs of previous prophets also apply to the Muslims if there is no direct text to the contrary.-JZ]
12) Cf., al-Maawardi, al-Ahkaam al-Sultaaniyyah, p. 75.
13) Cf., al-Tabari, Jaami al-Bayaan, vol. 13, p. 6.
14) Cf., al-Qurtubi, al-Jaami li-Ahkaam al-Quraan, vol. 7, p. 215.
15) Cf., al-Zamakhshari, al-Kashaaf, vol. 2, p. 263.
16) Ahkaam al-Quraan, vol. 3, p. 1092.
17) Ibn Taimiyyah, al-Fataawa, vol. 20, p. 56.
18) Cf., al-Tabari, quoting from al-Suddi, ibn Zaid and others, Jaami al-Bayaan, vol. 13, p. 6.
19) Ibn Taimiyyah, al-Fataawa, vol. 21, p. 56.
20) Ibn Taimiyyah, al-Fataawa, vol. 30, pp. 356-360.
21) [Perhaps this statement by the author is somewhat strong. He has noted that there is a difference of opinion on this issue among the scholars with each side presenting their evidence. Simply based on his own presentation of the issue-and especially given the fact that he did not discuss the question of the example given being of a Shareeah before that of the Prophet Muhammad (peace and blessings of Allah be upon him)-one cannot say that one opinion is definitely stronger than the other. Hence, as the author himself has concluded on other issues, this is an issue in which there is room for disagreement and neither view should be considered extreme. Allah knows best.-]Z]
22) Al-Hijrah, p. 10.
23) Al-Khilaafah, vol. 5, p. 13.