Posse Comitatus is long for “posse” which is the ability of law enforcement to deputize citizens.
Posse Comitatus prohibits the military from performing police duties in the US.
Feds using military equipment is not a violation of posse comitatus and same applies when feds are enforcing federal law.
Feds can take control of a sheriff’s office, but if the governor says NO then the sheriff should not assist the feds.
In states where the governor can dismiss a sheriff this could happen and the feds can’t “appoint” a sheriff - the sheriff says NO and refuses to cooperate, and if the feds try to use force against same, the governor can callup militia to oppose the feds involved.
No, Feds are not able to “take over” a Sheriffs office. Not without a DOJ patterns and practices lawsuit ending in a ruling, or a consent decree.
Despite hit movies, Feds cannot stroll in and “take over” a case, or direct a Sheriff or his Deputies to do as the order.