WASHINGTON—Housing and Urban Development Secretary Julián Castro broke a federal law restricting partisan activities by government employees in an April interview that touched on presidential contenders Hillary Clinton and Donald Trump, a federal watchdog office said Monday.

The U.S. Office of Special Counsel said it concluded remarks made by the cabinet secretary in an interview with Katie Couric for Yahoo! News—where he praised Mrs. Clinton, the presumptive Democratic nominee, and criticized Mr. Trump, the presumptive Republican nominee—violated the Hatch Act.

“Taking off my HUD hat for a second and just speaking individually, it’s very clear that Hillary Clinton is the most experienced, most thoughtful and most prepared candidate for president we have this year,” Mr. Castro said in the interview. He added Mr. Trump has shown “he’s just not prepared for the office” and that the Republican presidential contender “clearly does not even get the basic functions of our government.”

Mr. Castro made the comments while appearing in his official capacity as HUD secretary, the office said. Under the Hatch Act, federal employees are permitted to express their personal views on political issues, but not while they are conducting business under their government titles.

The special council’s office sent the report to President Barack Obama, who can decide whether the matter requires disciplinary action.