The stress of living conditions, similar to infections, alters animal immunity. High population density is empirically considered to induce prophylactic immunity to reduce the infection risk, which was challenged by a model of low connectivity between infectious and susceptible individuals in crowded animals. The migratory locust, which exhibits polyphenism through gregarious and solitary phases in response to population density and displays different resistance to fungal biopesticide (Metarhizium anisopliae), was used to observe the prophylactic immunity of crowded animals. We applied an RNA-sequencing assay to investigate differential expression in fat body samples of gregarious and solitary locusts before and after infection. Solitary locusts devoted at least twice the number of genes for combating M. anisopliae infection than gregarious locusts. The transcription of immune molecules such as pattern recognition proteins, protease inhibitors, and anti-oxidation proteins, was increased in prophylactic immunity of gregarious locusts. The differentially expressed transcripts reducing gregarious locust susceptibility to M. anisopliae were confirmed at the transcriptional and translational level. Further investigation revealed that locust GNBP3 was susceptible to proteolysis while GNBP1, induced by M. anisopliae infection, resisted proteolysis. Silencing of gnbp3 by RNAi significantly shortened the life span of gregarious locusts but not solitary locusts. By contrast, gnbp1 silencing did not affect the life span of both gregarious and solitary locusts after M. anisopliae infection. Thus, the GNBP3-dependent immune responses were involved in the phenotypic resistance of gregarious locusts to fungal infection, but were redundant in solitary locusts. Our results indicated that gregarious locusts prophylactically activated upstream modulators of immune cascades rather than downstream effectors, preferring to quarantine rather than eliminate pathogens to conserve energy meanwhile increasing the "distance" of infectious and target individuals. Our study has obvious implications for bio-pesticides management of crowded pests, and for understanding disease epidemics and adaptiveness of pathogens.