Why do lymph glands become swollen?

Infection, cancer. Lymph nodes swell when they 'catch' a virus or bacteria. Immune cells multiply to fight the infx, causing swelling of the node (s). U can have 1 swell without other symptoms of illness. If it persists > 2-3 wks, get checked out. If a node is painful, it's more likely due to infx than something like cancer. The nodes 'catch' cancer cells that multiply & enlarge the ever-growing nodes.
Monitoring Centers. Lymphatic system absorbs/carries things too big to go into the arteries/veins like bacteria eaten by white cells and digested food. Lymph nodes "taste" the lymph for anything bad like bacteria, viruses, cancers, etc. When it detects a problem, it alerts the immune system and your body reacts. They enlarge in response to the inflammation they create when they react. They shrink when all is well.