Mules are sterile because they have an odd number of chromosomes, which affects the production of sperm. Because a mule is the result of a horse and donkey mating, the chromosomes do not add up correctly and create the genetic defect of sterility.
The mix up occurs when the chromosomes from the horse and the donkey combine. Instead of being similar, these chromosomes are different. Because these chromosomes can't find the matching partner, the fetus does not make sperm for a mule or eggs for a molly.
While extra genes often cause genetic defects in people that affect cognitive abilities and physical appearance, the mismatch of chromosomes are generally harmless in the mule.