There is current no definite explanation for how autism spectrum disorder happens. The best evidence available today appears to support both environmental and genetic/physiology risk factors.
Environmental Risk Factors - According to the DSM-5, environmental risk factors may include advanced parental age at time of birth (especially the mother's), low birth weight, or fetal exposure to valproate, which is a medication primarily used to treat epilepsy and bipolar disorder and to prevent migraine headaches. It can also be used "off label" to treat other psychiatric conditions.
Genetic and physiological risk factors - Based on research done with twins, the heritability estimates for autism spectrum disorder range from 37% to as high as 90%. According to the DSM-5, as many as 15% of cases of autism spectrum disorder appear to be associated with a known genetic mutation associated with the disorder. However, even when that mutation is present, it does not automatically follow that the person will be diagnosed with the condition. Risk in other cases appears to involve multiple genes and maybe even hundreds of parts of genes that contribute to the development of the disorder.