According to canon, Merlin studied at Hogwarts. He eventually joined the court of King Arthur and used his tremendous magical skills to help build the kingdom of Camelot where muggles and wizards could work and live together helping each other.
That being said, I think Rowling's version of Merlin must be based on Geoffrey of Monmouth's work, which is why she would say Merlin was a student at Hogwarts. The way I see see it, it could have been the other way around. Merlin's legend goes back as far as the 6th century, several centuries before Hogwarts was built.
Merlin could have been the teacher of one or several of the founders. Though it would be a paradox given that Merlin defended muggles, I think he could have been Slytherin's teacher: There is a little known version in which Merlin is born from the union of a woman and a Sylph, destined to be the saviour of the old way and the protector of pagan gods against the spread of Christianity in Great Britain. He was first an expert in dark magic before he "saw the light" and became the benevolent character most people know. We know the Hogwarts four met and build Hogwarts as they were already very experienced in the magical arts. We also know wizards can live considerably longer than muggles; Slytherin was a very old man and could have prolonged his life by magical means, perhaps even with the help of the dark arts.
My point is, considering the above mentioned, though not canon, it's not far-fetched to think that Merlin being born around 600 AD, could have met young Slytherin around 750 AD (decades after the destruction of Camelot and the death of King Arthur) took him as a student, eventually died (or not!) around 900, and left Slytherin with a treasure trove of magical knowledge and skills he would want to share with young wizards associating first with Gryffindor, impressed by his transfiguration skills, and eventually meeting Hufflepuff and Ravenclaw to create this magical haven we now know as Hogwarts.