Depression can cause people to withdraw from friendships or be avoided by others, protecting others from exposure to that depression. Yet, researchers observe depression contagion, particularly among adolescents. We address this empirical puzzle by examining the role of gender in structuring friendship networks and the implications for isolation and the spreading of depression. Using stochastic actor-based models of friendships among 421 adolescents from mixed-gender, all-girls, and all-boys classrooms in six Taiwanese high schools, we find that networks with only girls are characterized by high reciprocity and low transitivity. This, in turn, facilitates the withdrawal of depressed girls from interactions. In contrast, networks with all boys create more opportunities for depression to spread through interconnected pathways. Our computational experiment further demonstrates that local preferences governing friendship choice influence levels of network connectivity. This, coupled with depression withdrawal and peer influence, shapes depression prevalence at the network level. These findings refine our understanding of the mechanisms through which friendships expose boys and girls unequally to health risks of depression.