the worm or grub of various insects (especially a fly), formerly supposed to be generated by corruption, late 15c., magat, probably an unexplained variant of Middle English maddok, maðek "earthworm, bedbug, maggot," from Old English maða "maggot, grub," from Proto-Germanic *mathon (source also of Old Norse maðkr, Old Saxon matho, Middle Dutch, Dutch made, Old High German mado, German Made, Gothic maþa "maggot").
Figurative use "whim, fancy, crotchet" is 1620s, from the notion of a maggot in the brain. Hence maggotry "folly, absurdity" (1706).