Well, everyone has their own versions of the mysterious history of pokemon, even the people of different regions within the pokemon franchise. But here I'm going to explain how I think all the legendaries tie in.
Originally, there was Mew, who is a psychic type who probably became a blip in emptiness, and gave birth to more types of pokemon. Supposedly, Mew created Arceus, who, according to Sinnoh Legend, created all of the universe. Within that universe, he created Palkia who created matter and space, and Dialga to give time to that matter. Giratina was also formed soon after and controlled anti-matter, one of the most dangerous and deadly forces and with his creation, Giratina formed the Distortion World. Consciousness was born, with Azelf holding willpower, Uxie with knowledge, and Mesprit with emotion. Somewhere in here Jirachi formed and began to lay dormant. All of these pokemon have incredible power.
Heatran was born and crawled out of the Earth's core at times, but was calmed by Kyogre who became and developed water on Earth, covering the whole planet in water, and then Groudon arose to create land masses for even more pokemon. But the fights continued more and more, and in order to calm the two forces, Rayquaza was born from the sky to wear away at both the land and the sea. Celebi became to be, to give plants and forests to color that land and was able to skip time in order to better protect the forest. With the forest came, seasons, a time to grow and a time to rest. With this came Moltres to bring about warmth, but Articuno cooled his fire, while Zapdos was the one sent to balance the two of them.
Of course, the moon had been drawn to Earth at some point in time, and Cresselia was born. She in connection with the three beings of consciousness, developed and gave consciousness to all lifeforms. But when the moon doesn't shine, a night of no moon, Darkrai instilled fear into the hearts of all conscious beings. Manaphy and Phione, were born into the sea, because one could clearly see Kyogre was put dormant due to Rayquaza's appearence. Manaphy was the new gaurdian of the sea. And with Celebi being so occupied with protecting the forest, another guardian of plant-life emerged; Shaymin. Shaymin, both in its land and sky forms, can purify any plant.
Eventually Ho-oh formed and so did its watery-counterpart Lugia, to which they created and/or revived the legendary dogs, Suicune, Entei, and Raikou. And as the human race began evolving the three golems began to form and protect the human race, from the Ice age, Stone age, and the Iron age at least until the humans could fend for themselves, in which case Rigigigas formed to take control over the three of them. And as human history continued, they discovered viruses due to the discovery of Deoxys and its forms.
Of course, in ancient Chinese mythology, Taoist thought and ideaolgy appeared, giving birth to Reshiram and Zekrom.
Feel free to respond with your own version or idea of the history ^^