Among eukaryotes, sexual reproduction is by far the most predominant mode of reproduction. However, some systems maintaining sexuality appear particularly labile and raise intriguing questions on the evolutionary routes to asexuality. Thelytokous parthenogenesis is a form of spontaneous loss of sexuality leading to strong distortion of sex ratio towards females and resulting from mutation, hybridization or infection by bacterial endosymbionts. We investigated whether ecological specialization is a likely mechanism of spread of thelytoky within insect communities. Focusing on the highly specialized genus Megastigmus (Hymenoptera: Torymidae), we first performed a large literature survey to examine the distribution of thelytoky in these wasps across their respective obligate host plant families. Second, we tested for thelytoky caused by endosymbionts by screening in 15 arrhenotokous and 10 thelytokous species for Wolbachia, Cardinium, Arsenophonus and Rickettsia endosymbionts and by performing antibiotic treatments. Finally, we performed phylogenetic reconstructions using multilocus sequence typing (MLST) to examine the evolution of endosymbiont-mediated thelytoky in Megastigmus and its possible connections to host plant specialization. We demonstrate that thelytoky evolved from ancestral arrhenotoky through the horizontal transmission and the fixation of the parthenogenesis-inducing Wolbachia. We find that ecological specialization in Wolbachia's hosts was probably a critical driving force for Wolbachia infection and spread of thelytoky, but also a constraint. Our work further reinforces the hypothesis that community structure of insects is a major driver of the epidemiology of endosymbionts and that competitive interactions among closely related species may facilitate their horizontal transmission.