The other answers correctly assert the origin of "cantrip" dating back centuries before D&D, but I'd like to add some context for how it made its way into D&D.
In Dragon Magazine #59 (March 1982), Gary Gygax wrote an article titled "Cantrips: Minor magics for would-be wizards". It introduced a large number of weak 0th-level spells, mostly having mundane uses like sweetening food or polishing boots.
It's important to note that Gygax wrote this article, because it was very much his style to take archaic English words from the dictionary and give them a specific meaning in D&D. He would also use intentionally obscure words, a writing style which people called "High Gygaxian". For example, here's a quote from a 2005 ENWorld forum post where he mentions it:
My own thesaurus has hand-written additions I have made over the years, and both of my main dictionalries are unexpurgated, one from 1910 the other from 1930.
In D&D 5th edition, mechanical needs saw cantrips promoted to more powerful spells.
The original meaning of the word "cantrip" is a term from the Scots language, originating from a term referring to a musical notation used by pipers, and which then came to mean a magical incantation. It's used to in the sense of magic in Rabbie Burns' poem Tam O'Shanter, from 1790:
Coffins stood round like open presses,
That shaw'd the dead in their last dresses;
And by some devilish cantrip slight
Each in its cauld hand held a light