In short, Merlin spent time as a madman, acting like a beast in the wilderness. Mary Stewart's wonderful Arthurian take on post-Roman Britain has him "lost" for several months after being drugged.
In truth, this may be Merlin's "natural state"; that is, originally, the character who comes down to us as the Merlin of legend may be based on a real figure whose chief feature was being not quite sane. This is the story of Myrddin Wyllt.
Myrddin Wyllt (pronounced like "murthin wilt") is a character in medieval Welsh legend (where many Arthurian stories originate). The name means "Myrddin the Wild"; he is also known as Myrddin Emrys (Emrys=Ambrosius), Merlinus Caledonensis ("of Caledonia"), and Merlin Sylvester's ("of the woods"). Born supposedly c.540CE, he was a bard (perhaps the chief bard) who goes mad after the Battle of Arfderydd. Having become irrational for some reason, he takes to the forest (some versions say the Caledonian Forest in Scotland). There he gains the power of prophecy (often associated with being not quite right in the head).
The "Life of Saint Kentigern" tells of the saint (also known as St. Mungo) encountering a madman in the Caledonian Forest named Lailoken or Laleocen in the late 6th century. A later (15th century) story about "Lailoken and Kentigern" includes the line "...some say he was called Merlynum." This link between the two names may have been influenced by a 12th (?) century poem, a dialogue between Myrddin and his sister (?) Gwendydd in which his sister calls him Llallwgan, the Welsh form of Lailoken.
Some scholars assume a conflation of several different characters:one in Wales, one in Scotland, maybe more. The Merlin story is convoluted, obscure, and largely probably untrue, but much of it starts with a mad bard. Because of the time period, his legend much later became linked to Arthur's court as a wise man and prophet. But in the beginning, his chief feature is his sudden madness.
Why did he go mad after the Battle of Arfderydd? It was an important turning point, one of the "Three Futile Battles of the Island of Britain," which I'll explain next time.