Breeding Groups
Pokemon are only compatible with other Pokemon that are similar in nature. Any Pokemon that can breed falls into what is called an "egg group." Any Pokemon from that egg group is able to reproduce within the group (provided that the other Pokemon is of the opposite gender). The legendary Pokemon group, which exclusively contains all of the legendary Pokemon, refuse to breed in captivity.
Ditto Breeding
Ditto is a generous Pokemon that resembles a large blob. In battle, it can mimic whatever Pokemon it is fighting. Dittos are useful for breeding because they can essentially be used like a wild card. If you pair up any Pokemon that can breed with a Ditto, then the resulting egg will be the Pokemon Ditto was paired with. Dittos even breed with other genderless Pokemon. Despite Ditto seeming to break the traditional method of breeding, it will still not produce an egg with legendary Pokemon.
Reasoning
Legendary Pokemon make up the large percentage of a very short list of Pokemon that cannot breed, which makes sense. Legendary Pokemon are extremely powerful, special Pokemon that you only see once during the entire game. If players were able to breed these Pokemon, players could have multiple copies of this powerful Pokemon, and users who have not even encountered legendary Pokemon in their game could be traded legendary breeds from their friends.
Manaphy
Manaphy, found in "Pokemon Diamond/Pearl," is the one abnormality to the general breeding rules. Manaphy is technically a legendary Pokemon, but it does have a connection to the breeding process. If you catch Manaphy and pair it with a Ditto, it will produce an egg. This egg, however, will not produce another Manaphy or Ditto. Instead, the egg will hatch into a Phione.