Well, many countries refer to e.g. the legislative branch of government, but this is semantic. Plainly, as you say, executive branches of government can break the law. Specific governments can be illegal, but the concept of government is, by definition, legal.
Law has no retroactive effect, so if the new government came into the power through a coup, it will be illegal even if they will illegally adopt a constitution a bit later. That's why any real revolution ends with elections or another legitimate and legal way to form new government.
I don't think this really holds up. The US, by this rule, would still be an illegitimate government under the laws of my country, given they had a revolution to throw us off as oppressors. Their adoption of constitutional rights and democracy made them morally legitimate, but if a dictator had seized power instead, their edicts would be no less legal than laws passed by congress - they would still be laws.