Actually, ditto can’t breed because they lack reproductive organs in their original forms. Instead, they reproduce via budding, so technically, all ditto are really the exact same organism genetically.
However, ditto do not create clones of regular pokémon, although this is an interesting theory. What actually happens is that a ditto assumes the form of whatever pokémon they choose to mate with, but there’s an asterisk to this concept. It’s true that on the battlefield, ditto become exact copies of their chosen target, but off the battlefield, they can actually assume whatever form they want. (They simply need a visual example in order to create an accurate copy.) What this means is that ditto gain the reproductive organs of whatever pokémon they choose, but they can only do so when transformed. At the same time, while on the battlefield, ditto assume the exact form of the pokémon in front of them because it’s quicker, off the battlefield (such as in a breeding pen), they can sometimes get “creative” by assuming the form of a member of the opposite biological sex. For example, on the battlefield, a ditto may transform into a male charizard because a male charizard is the closest example and thus the quickest thing to turn into, but in the breeding pen, a ditto may attempt to create female charizard reproductive organs instead to coincide with the male’s.
On that note, pokémon such as magnemite or staryu or other so-called genderless pokémon actually employ a wide variety of reproductive methods. After all, they need some level of breeding in order to maintain their wild populations. It’s just that they don’t lay eggs in the wild—or they don’t as we know it.
Take the staryu and starmie, for example. These are actually biologically fascinating pokémon, as they are capable of breeding one of two ways, depending on how stressful of an environment they’re in. The most common method is by fission, or the act of splitting themselves neatly through their core to produce two genetically identical specimens. This tends to be quicker, as it requires no gestation time, and the resulting staryu (the children are always staryu, making this a very rare case of deevolution) are capable of fighting immediately. Unfortunately, as one can guess, this reverts the parent to a heavily weakened state. The process essentially resets its genetic code all the way back to its preevolved form, and the resulting children each need to retrain their bodies to use the most powerful attacks their parent knew. Still, it’s the preferred method because the other method, spawning, requires a gestation period and thus can only be performed in situations wherein the parent staryu or starmie are capable of defending their offspring. To summarize this method, keep in mind that staryu and starmie are actually hermaphroditic, not truly genderless. That is to say, all members of this evolutionary family possess both male and female organs, and when breeding, these organs send out clouds of both eggs and sperm to mix with another staryu or starmie’s eggs and sperm. The resulting dust settles on the ocean floor and begins its slow march towards forming new staryu … assuming no hungry magikarp stop by, anyway.
Meanwhile, voltorb reproduces by electrical sporogenesis. When in contact with either eggs laid by ditto or metal and plastic debris (empty poké balls seem to be preferable), voltorb discharges spores containing a mix of its own genetic material and electrical energy. This fertilizes and jump-starts an egg, but when in contact with debris, it draws the material together via static, melds it together, and animates the resulting object to form a new voltorb specimen.
Then, of course, you have porygon, which simply create their own offspring exactly as you think they would (that is, by copying their code and writing their own young into existence).
Hopefully, you get the idea from there.
Where ditto come in, meanwhile, is quite simple. Oftentimes, asexual reproduction is the more costly method to use, especially for trained pokémon. Imagine, for example, that your beloved starmie, who you’ve trained for years, suddenly split itself into two staryu, and you had to start all over again with two new pokémon. Trainers prevent this by pairing their pokémon off with a mate: ditto. By encouraging them to fertilize eggs ditto creates (by manifesting egg-laying organs that are capable of generating eggs that are compatible with these species, as mentioned above), genderless pokémon may relieve their natural drives to reproduce, thus preventing them from, say, splitting themselves in half to form new entities.
In other words, ditto reproduce by budding, most other “genderless” pokémon employ any of a variety of reproductive methods (that don’t use eggs as we know them), but together, they lay eggs because ditto is mimicking them on a genetic level but conceiving of an egg-laying structure that can produce something for them to fertilize.
Except porygon, anyway. It seems all ditto and porygon do is write code together to create an artificial egg. It’s quite entertaining, actually. They’re far better at quality assurance than I am, and it’s a shame the Pokémon Association won’t let me hire them as actual system administrators.