During outbreaks, locust swarms can contain millions of insects travelling thousands of kilometers while devastating vegetation and crops. Such large-scale spatial organization is preceded locally by a dramatic density-dependent phenotypic transition in multiple traits. Behaviourally, low-density ‘solitarious’ individuals avoid contact with one another; above a critical local density, they undergo a rapid behavioural transition to the ‘gregarious phase’ whereby they exhibit mutual attraction. Although proximate causes of this phase polyphenism have been widely studied, the ultimate driving factors remain unclear. Using an individual-based evolutionary model, we reveal that cannibalism, a striking feature of locust ecology, could lead to the evolution of density-dependent behavioural phase-change in juvenile locusts. We show that this behavioural strategy minimizes risk associated with cannibalistic interactions and may account for the empirically observed persistence of locust groups during outbreaks. Our results provide a parsimonious explanation for the evolution of behavioural plasticity in locusts.