Legendary Pokemon are all in the "undiscovered" egg group.
Presumably, the theory is they're too rare and do not frequent the human world enough to be studied, therefore they're origins are not fully explored/ confirmed.
Ditto exists in its own egg group, "Ditto", and you can breed two Dittos together and you'll get Ditto offspring.
While Manaphy can breed, it can only breed Phione, and Phione can only breed Phione. Manaphy might as well be in the undiscovered egg group, since it doesn't reproduce its own species.
There are some Pokemon that we know the origins of. The Lake Trio and the Time/ Space Trio were all created by Arceus. These two trios don't breed for offspring, but instead are replaced by new creations Arceus makes when one dies/ is caught by a trainer. Arceus itself is a god Pokemon, which presumably was not created by anything else.
According to some legends, Arceus is the creator of the Pokemon world, so perhaps Arceus created everything.
There was an episode which featured a Baby Lugia named Silver, who had a parent Lugia, so presumably Lugias are a species that breed.
Then there's elemental embodiments like Suicune, Entei and Raikou. They were created by Ho-oh from the three Pokemon souls that died in the burnt tower.
Most legendaries seem to be created from natural phenomena, so they were created by an element, or created by other legendaries, unlike regular Pokemon who breed to reproduce. That's where they come from.
Well, presumably anyway. Never question Pokemon logic.