Question: Is it permissible to assist an oppressor in acts of good, projects of righteousness, and to accept his rewards and compensations for that, or not?
Answer – and from Allah is success: That is permissible, and it is not far-fetched that it may even be obligatory to assist him in what is obligatory, if no harm results from that; due to His, Exalted is He, saying: “Cooperate with one another in goodness and righteousness, and do not cooperate in sin and transgression.” [Al-Mā’idah:2] And there is no objection to accepting his rewards and compensations, but on the condition that no harm results from that in the future, such as that the oppressor may, by means of that, draw him into assisting him in falsehood, justifying his corrupt actions, keeping him company, and the like.
Source: Min Thimār al-ʿIlm wa al-Ḥikmah vol.2