Maggoty. Whimsical, full of whims and fancies. Fancy tunes used to be called maggots, hence we have “Barker's maggots,” “Cary's maggots,” “Draper's maggots,” etc. (Dancing Master, 1721.)
When the maggot bites.
When the fancy takes us. Swift tells us that it was the opinion of certain virtuosi that the brain is filled with little worms or maggots, and that thought is produced by these worms biting the nerves. “If the bite is hexagonal it produces poetry; if circular, eloquence; if conical, politics, etc.” (Mechanical Operation of the Spirit.
Instead of maggots the Scotch say, “His head is full of bees;” the French, “Il a des rats dans la tête;” and in Holland, “He has a mouse's nest in his head.” (See Bee.)
Source: Dictionary of Phrase and Fable, E. Cobham Brewer, 1894