FBI agents are particularly restricted in what they may do or not do. This is partially specified by law, and partially a professional norm. Both law and custom allow FBI agents (as well as all other governmental staff) to have opinions. However, they must be careful about how they express those opinions.
Federal Employees Have Restrictions
The United States Constitution protects the ability of all people to engage in political speech freely. However, federal employees are in a tough place: while they have the right to political speech, they can't use their office to push their (personal) agenda.
The Hatch Act governs what kinds of partisan activities federal employees may participate in. In general, civilian federal employees (except a few, such as the President and Vice President) may participate in public life with a few exceptions:
- They may not run for office in partisan elections.
- They may not use their official authority or influence to influence an election.
- May not do anything to purposefully contribute to the success or failure of a candidate while on duty, while in their office, or using government property.
- May not solicit, accept, or receive campaign donations.
FBI Agents are Somewhat Special
Within the Hatch Act there is a list of agencies labelled "further restricted". Employees of these agencies are especially restricted in the kinds of partisan activities they can pursue.
For example, while all federal employees may not actively campaign for anyone under certain circumstances, further restricted employees may not actively campaign at all. This means they may not make public statements supporting candidates, parties, or platforms, make those posts on social media, distribute campaign literature, etc.
Also, further restricted employees may not:
Hold office in any political organization (including political parties, but also politically-oriented community groups).
Encourage subordinates (even tacitly) to attend partisan events.
On the other hand, the Hatch Act explicitly protects the rights of federal employees (even 'further restricted' ones) to express their opinions on politics. However, that commentary cannot be either coordinated with a partisan group or aimed at actually influencing an election.
The Federal Bureau of Investigation's employees are further restricted. Being critical of the President is not a restricted activity - in fact it's protected (as the ability to express opinions).
Even though the Hatch Act does not prevent an FBI agent (or anyone else) from being privately critical of the President, there is a set of professional norms which make it unpalatable. In many agencies, it is equally important to avoid the appearance of partisanship as well as actual partisanship.
This is partially based on my experience: I work for a state agency. Even though we are not covered by the Hatch Act, our internal policies are almost identical. And the reason is easy: in practical terms, the appearance of being biased would compromise our role in government. Similarly, even if the agent-in-question really is entirely unbiased (and non-partisan) the appearance of being partisan may be risky enough to justify removing them from that team.