Origins
Wizard is a word that Tolkien made noble, but which began as something closer to an insult. It is formed from Middle English wis meaning 'wise' plus the suffix -ard — the same ending found in drunkard, coward, and bastard.
The suffix -ard, borrowed from Old French, carries a distinctly pejorative tone. It implies excess or contempt. A drunkard drinks too much; a coward fears too much; a wizard, originally, knew too much — or knew things they shouldn't.
Development
The connection between wisdom and magic is ancient. In medieval England, 'wise men' and 'wise women' were the local healers, herbalists, and astrologers. Their knowledge of plants, stars, and the natural world seemed supernatural to their neighbours. The word wizard captured this suspicion: this person is wise, but suspiciously so.
The deeper etymology connects wizard to the Proto-Indo-European root *weid- meaning 'to see' or 'to know'. This same root gives us wise, wisdom, wit, witness, and — through Latin vidēre — vision, video, and evidence. A wizard, a witness, and a video all share the same ancient root: to see clearly.