Sex differences in behaviour extend to cognitive-like processes such as learning, but the underlying dimorphisms in neural circuit development and organization that generate these behavioural differences are largely unknown. Here we define at the single-cell level-from development, through neural circuit connectivity, to function-the neural basis of a sex-specific learning in the nematode Caenorhabditis elegans. We show that sexual conditioning, a form of associative learning, requires a pair of male-specific interneurons whose progenitors are fully differentiated glia. These neurons are generated during sexual maturation and incorporated into pre-exisiting sex-shared circuits to couple chemotactic responses to reproductive priorities. Our findings reveal a general role for glia as neural progenitors across metazoan taxa and demonstrate that the addition of sex-specific neuron types to brain circuits during sexual maturation is an important mechanism for the generation of sexually dimorphic plasticity in learning.