Question: What do you say regarding employment with the state?
Answer — and Allah is the One who grants success: Employment with the state—any state, whether just or unjust—is permissible with two conditions:
First: that one does not wrong anyone in his post or his work.
Second: that one does not assist or cooperate in wronging anyone, nor strengthen the hand of the oppressor. If the matter is as such, then there is no impediment to such employment, so far as I know—though keeping away from it is safer. For we have often seen those who enter state employment become entangled in perils such as bribery, injustice, and the like. For some reason, the Messenger (May Allah bless him and his family and grant them peace) warned against assuming judgeship and adjudicating between people.
If a person must be employed, let him choose for himself among posts those closest to safety and farthest from injustice—such as teaching, or working in electricity or telephone services, and the like of matters devoid of what we have mentioned.
Source: Min Thimār al-ʿIlm wa al-Ḥikmah vol.2