"tube-shaped food made of dried wheaten paste" [Klein], 1590s, from southern Italian dialectal maccaroni (Italian maccheroni), plural of maccarone, name for a kind of pasty food made of flour, cheese, and butter, possibly from maccare "bruise, batter, crush," which is of unknown origin, or from late Greek makaria "food made from barley."
Originally known as a leading food of Italy (especially Naples and Genoa), it was used in English by 1769 to mean "a fop, a dandy" ("typical of elegant young men" would be the sense in "Yankee Doodle") because it was an exotic dish in England at a time when certain young men who had traveled the continent were affecting French and Italian fashions and accents (and were much mocked for it).
There is said to have been a Macaroni Club in Britain by 1764, composed of young men who sought to introduce elegancies of dress and bearing from the continent, which was the immediate source of this usage in English. Hence the extended use of macaroni as "a medley; something extravagant to please idle fancy" (by 1884).