Ditto were created by Pokemon researchers (perhaps working for Team Rocket) trying to replicate Mew. This explains why they are the only Pokemon to naturally learn the move Transfrom and also why they share the same colors in both regular and shiny, and even the same weight (8.8 lbs).
A large number of them were manufactured in the Pokemon Mansion located on Cinnabar Island, which explains why they are found there exclusively in the Yellow version (with the exception of Cerulean Cave, which is a weird place regardless). They were deemed a failure and when the Mansion was abandoned, the Ditto managed the spread across Kanto and further. They were able to easily transport themselves off the island by transforming into the Water Pokemon surrounding the island and swimming away, or perhaps through the occasional Flying type.