Forget for a moment about the Orwellian Big Brother aspects of government agencies that feel nothing is wrong with targeting certain groups for harassment (for example the IRS, Justice, and even the EPA though there's no headline scandal right now). Instead, let's focus on what the underlying problem is - that which enables the government agency to feel they are insulated from having to answer to anyone about anything.
There are three reason I can think of that might account for that type of behavior - political motivations aside. These reasons are not meant to be collectively exhaustive but they likely explain a significant percentage of why agencies think this sort of behavior is acceptable.
Firstly, these agencies may feel that they are the government's equivalent of too big to fail, i.e. they are too big to answer to anyone because of the sheer titanic mass behind them. That's distressing from the perspective that they are relying on their size to intimidate or to squash any potential resistance. That sounds a lot like tyranny.
Another possible reason is that because these agencies have become so large, there is no sufficient locus of responsibility. In other words, no one answers directly to anyone that can be tied back to anyone in an administration. That seems suspiciously convenient. Those in charge of the executive branch can speak some ideology and have it obeyed without any accountability on their part or the part of their subordinates. Either that means a structure prone to abuse due to that lack of specific responsibilities, or a structure prone to abuse because it can be blamed on the expanse of the government and it being beyond manageable.
That's the type of thinking that led to Nazi Germany's death camps. "I was just following orders" is a way to abdicate personal responsibility;
Large-scale evil requires surrender of autonomy, coercion by a central authority and a willingness to follow orders.
With no personal responsibility to stand up and say no to unfair policies and processes, government agencies become especially subject to misguided actions. It's always someone else's fault. It's always above everyone's pay grade.
That does nothing of course, to excuse inexcusable behavior. Nor does that lack of locus of responsibility preclude the "too big to answer to anyone" mentality either.
Another possible motivating factor is that a government department's mandate, by being expanded and growing, continues the justification for that department's continued existence. In other words, job security is a factor.
As Oscar Wilde said, “The bureaucracy is expanding to meet the needs of the expanding bureaucracy.”
Government departments are genetically encoded to expand - to propel forward, and find new reasons to justify their own existence. That leads to massive spending requirements to support these departments and continually diluted and expanded mandates that go well beyond common sense.
Some of the lessons of history still have not been learned. Governments are still designed without brakes. And anything unable to stop, eventually crashes into something.