It was legitimate in the same way that a dictator’s rule over their people is legitimate or hangings for blasphemy are legitimate. It may be technically written on a piece of paper somewhere, but someone who got less votes becoming president over someone who got more is not representative of a genuinely legitimate democracy.
In the mirror situation, Trump would’ve just had the opposing court justices assassinated and then installed puppets that would rule that those assassinations were official acts.