There doesn't seem to be any real question of the legitimacy of the Mede dynasty; no one seems to be actively challenging them. Falk Firebeard pointed out, that if Queen Potema returned from the dead, she would be the only living Septim -- the implication being that she would challenge the Medes.
It's fairly clear that High King Torygg was loyal to the Empire, and presumably there was some sort of formal recognition of that when he or the current emperor was crowned (whichever came first), that being the sort of thing that gets included in such rituals; it would have been conspicuous by its absence.
I haven't followed the Stormcloak quest line, but I don't have the impression that Jarl Ulfric makes a point of the Mede dynasty being illegitimate. I don't think that's a point he'd omit if he thought it would play.