There's an entire field (although a small one) dedicated to this called Evolutionary Psychopathology. The idea is that mental illnesses are failure modes of adaptive phenotypes. For example high functioning autistic couple could produce a severely autistic child.