It's simple enough, really. In America, if you work for a federal agency, you can't use your taxpayer-funded office to advocate for your political beliefs. Americans deserve a federal government that works for all of them, not just the people they agree with.

That principle was enshrined in law in 1939 as the Hatch Act, and on Monday, a federal watchdog group decided that Housing and Urban Development Secretary Julian Castro violated it when he praised Hillary Clinton in an interview with Yahoo News's Katie Couric.

Castro is on Hillary Clinton's shortlist for her vice-presidential pick, so this comes at an awkward time for him. He apologized, and the upshot is he probably won't face any punishment -- since it's up to the president to decide what to do, and we've gotten no indication the White House plans to double down on this to make life harder for one of Clinton's potential vice-presidential picks.

But this is an issue that comes up from time to time, especially among Cabinet secretaries, who are often both leaders of federal agencies and high-profile surrogates for the president they serve. So let's break down what Castro did wrong and why:

The offending comment: "Now, taking off my HUD hat for a second and just speaking individually, it is very clear that Hillary Clinton is the most experienced, thoughtful and prepared candidate for president that we have this year."

That came in an April 4 interview with Couric. Castro was talking about a new HUD policy to expand Internet access to low-income children, and then Couric switched to politics -- as journalists do -- by asking him why he's endorsed Clinton.

Why that was wrong: Announcing that he was taking "off his HUD hat for a second" wasn't a clear enough delineation between his private and public life, according to the ethics watchdog officials who oversee these things. While he was conducting the interview, the official HUD seal was behind him, and Couric addressed him as "Secretary Castro." They spent the first seven minutes of an 18-minute interview talking about HUD policies.

A reasonable person listening to the interview might think Castro was praising Clinton -- and, later in the interview, criticizing Trump -- in his official capacity as a government official, according to the watchdog group.

"Secretary Castro’s statements during the interview impermissibly mixed his personal political views with official agency business," U.S. Office of Special Counsel Carolyn Lerner wrote in a letter to President Obama, "despite his efforts to clarify that some answers were being given in his personal capacity.

What he should have said: Something to the effect of: "That's a political question and I'm not going to answer it while giving an interview as head of HUD."

What he did say afterward: In the letter Lerner sent to the president, Castro is quoted as saying he thought at the time he was complying with the Hatch Act but now realizes he didn't:

"My aim was to make clear to anyone viewing the broadcast that, when answering those direct questions regarding candidates, I was not acting in my official capacity … I now have watched the recording of the interview and appreciate that, while my intention was to avoid any blurring of roles and make clear that I was not speaking as a representative of HUD, that fact may not have been obvious to viewers. "

When other people got in trouble for something similar: In 2012, Kathleen Sebelius, then the secretary of health and human services, was talking to a gay rights organization about Obamacare when she said one of the imperatives is that "we make sure that in November [President Obama] continues to be president for another four years." The same watchdog agency that's reprimanding Castro now also reprimanded Sebelius.

And, as Politico's Josh Gerstein points out, also in 2012, Hilda Solis, then the secretary of labor, was under investigation for potentially violating the Hatch Act for allegedly helping fundraising for Obama's reelection campaign -- a no-no under the law.

So can Cabinet secretaries ever talk politics? Yes, if it's clear they're acting as private citizens.

Their title never officially goes away, of course, but they can given an interview about politics when outside of the office, when the interview pertains mostly or entirely to politics, and when it's generally more clear that they are acting as a private citizen than a public official.

Any mix of the two is unacceptable. As Castro said in his apology: "I now understand that the mixed-topic interview, even with a proviso, is problematic."