The chemistry of the runny nose revealed:
Sugar chains are attached to a protein backbone in mucus cells, with the contraption released out into the open. These glycoprotein molecules rapidly and aggressively suck up water until they are plump, slick, and slimy. To an invader, this is a nightmare to navigate: tangled chains of protein and sugar, with every nook and cranny crammed with water molecules. (Boogers are when these chains become ever more tangled, finally resulting in a rubbery ball of partially dried-out snot. Neat!) The body adds antimicrobial enzymes to this mix, which digest the invading organisms as they slowly attempt to chew through this barrier and reach the thin underlying lining of cells.
Using Maria Jesus Portalatin's book Consuming the Inedible: Neglected Dimensions of Food Choice, Maggie Koerth-Baker examines whether there might be a biological reason for eating boogers:
[N]asal mucus is about 95% water, so there's a possibility that you might expect more mucus eating in arid places. But nobody has ever done the studies necessary to test that hypothesis out. Her main hypothesis—also untested—is that eating mucus might help prime the body's immune system, allowing it to have more contact with weakened forms of potential pathogens so it can better detect and destroy those pathogens later. In other words, she thinks that eating your boogers is sort of like self-immunization.