This is a recurring theme throughout mythology and history.
Speaking in unknown languages, frenzied or otherwise 'mad' behaviour, is associated with prophecy and future-telling (especially shamanic future-telling) or otherwise unexplainable knowledge in a very large amount of cultures.
In some, rituals approximating a frenzy or madness are used to aid prophecy, such as certain dances or actions (including self-harm, drug use, and more esoteric practices).
Although the exact explanation for this association varies amongst cultures and specific sources, it was often that accessing some otherworldly source of knowledge caused the fit, words, or behaviour, as a side effect or as a cost/requirement. Sociologically, these kinds of extreme effects often were taken as adding authenticity to the prophecy or other knowledge divined in this manner.
More modern versions of this exist both as offshoots of ancient (or theoretically ancient) traditions, and versions based on modern religions such as the pentecostalist (and other) beliefs related to speaking in tongues.
The vast number of potential mythological, cultural, and religious sources for this spell in Dungeons & Dragons means that, barring any indication from the original author, it is hard to narrow down where specifically this influence came from - especially given fantasy fiction at the time Dungeons & Dragons was initially devised made heavy use of mythological and original sources that could have pulled influence from any number of mythologies and 'alternative' religious practices popular at the time.