Who does the hanging?
A government can be given power, or extract it via violence. Either way there are humans behind every expression of "legitimacy".
Its always humans who give a government power. True, humans with guns can instill a lot of "legitimacy", and disproportionally so.