Legitimacy is derived from lex and has the same root as ‘legislation’. One sense of ‘legitimate’ is being in accordance with law or lawful (legality) Any lawful or ‘legal’ state is legitimate in this sense.
Closely related would be the more general notion of being in accordance with the established rules or procedures relevant to the matter at issue (e.g. a legitimate move in chess, the legitimate heir to the throne). These senses of ‘legitimate’, largely procedural and similar to the primary sense of ‘legal’ (being in accordance with the law), are not very useful for our normative inquiry.