Wikipedia explains this quite well:
The Three-Eyed Raven begins transferring knowledge to Bran as the army of wights arrives. While in a vision of Winterfell, Bran hears the cries of Meera Reed who is trying to save Bran's body while the Children hold back the wights. The Three-Eyed Raven advises Bran to listen to her, and Bran splits his consciousness by both remaining in the vision of the past and simultaneously warging into Hodor in the present. The Night King enters the cave and kills the Three-Eyed Raven. As Bran, Meera and Hodor make their escape, Leaf, and Bran's direwolf, Summer, sacrifice themselves to hold back the wights. Hodor closes the hideout's door behind them, keeping the wights inside while Meera escapes with Bran. Meera repeatedly orders Hodor to "hold the door" shut while they flee, which results in the Wights tearing him apart.
In the vision, Bran becomes overwhelmed by the split consciousness and unintentionally wargs into a younger version of Hodor in the vision, then known as Wylis, forging a connection between the past and present. With Bran's consciousness inside his head, Wylis suffers a seizure while hearing the echoes of Meera's orders and he begins to yell the words "hold the door" over and over, until they slur together and "Hodor" is all that's left that he can say.
So, up until the time that the vision/time-trip took place Wylis was "normal" but the event ripped his mind until "Hodor" was all he could say and that became his name.