Most animal model studies of autism spectrum disorders (ASD) were performed in males. Thus, little is known about the mechanisms underlying disease progression in females. Here, we searched for potential influences of sex and environment on gestational valproic acid‐induced behavioral abnormalities using hippocampal‐dependent tasks, and on number and morphometry of microglia of the molecular layer of the dentate gyrus (Mol‐DG). We compared male and females BALB/c control mice with BALB/c mice gestationally exposed to VPA with regards to exploratory activity and risk assessment in novel environments. Pregnant females and males on gestational day 12.5 received VPA in saline (600 mg/kg body weight) or an equal volume of saline by gavage. After weaning, female and male offspring were housed separately either in standard laboratory cages (SE) or enriched cages (EE). At 5 months of age, these mice underwent behavioral testing and had their brains processed for microglia IBA1 immunolabeling. Compared with control mice, VPA‐exposed mice exhibited abnormal behavior in exploring novel environments and assessing risk, and these effects were significantly greater in females than in males and less intense among mice from enriched cages. Three‐way ANOVA revealed that environment, sex and valproic acid conditions interacted and altered the behavior results. Microglia number and volume of the Mol‐DG were significantly higher in VPA‐exposed groups raised in standard cages. The results of counting the intersects of microglia branching on Sholl's circles analyzed with permutational MANOVA, demonstrated that in comparison with males, there was a greater reduction in the number of intersections in females raised in standard cages. These findings suggest that the increased microglia and morphological changes might be associated with behavioral dysfunction in ASD. Moreover, the somatomotor and cognitive stimulation of environmental enrichment started at weaning may be beneficial for reducing behavioral abnormalities and reduction of microglia response in adulthood.