Immune challenges during gestation are associated with neurodevelopmental disorders and can interact with stress later in life. The pituitary gland participates in endocrine- and immune-related processes that influence development, growth, and reproduction and can modulate physiological and behavioral responses to challenges. The objective of this study was to investigate the effect of stressors at different time points on the molecular mechanisms of the pituitary gland and detect sex differences. RNA sequencing was used to profile the pituitary glands of female and male pigs exposed to weaning stress and virally induced maternal immune activation (MIA), relative to unchallenged groups. Significant effects (FDR-adjustedp-value < 0.05) of MIA and weaning stress were detected in 1829 and 1014 genes, respectively. Of these, 1090 genes presented significant interactions between stressors and sex. The gene ontology biological process of the ensheathment of neurons (GO:0007272), substance abuse, and immuno-related pathways, including the measles disease (ssc05162), encompasses many genes with profiles impacted by MIA and weaning stress. A gene network analysis highlighted the under-expression of myelin protein zero (Mpz) and inhibitors of DNA binding 4 (Id4) among the non-stressed males exposed to MIA, relative to the control and non-MIA males exposed to weaning stress, relative to non-stressed pigs. The detection of changes in the molecular mechanisms of the pituitary gland could advance our understanding of disruptions in the formation of the myelin sheath and the transmission of neuron-to-neuron signals in behavioral disorders associated with maternal immune activation and stress.