It's a cruel, cruel world on Game of Thrones, and nobody got the short end of the stick quite like Hodor. Hodor's origin story has sparked interest since Bran first caught a glimpse of a young, speaking Hodor named Wyllis in one of his visions of Winterfell from the past. Episode 5 it was all, tragically, revealed, and Hodor was killed. But did Hodor know he was going to die on Game of Thrones?
When the White Walkers attacked the cave, Bran was stuck in a vision of Winterfell from when his father was a boy — it seemed like a much nicer place to be, honestly — and could not wake up despite Meera screaming at him. What ended up happening was that from the past, Bran warged into present day Hodor through past Wyllis, and thereby got Hodor to get up and carry Bran to safety and then, hold the door so that Meera and Bran could escape.
In the vision of the past, we saw Wyllis collapse and convulse while muttering "hold the door," until present day Hodor was killed by White Walkers. This episode is what messed up his brain forever. Are you crying yet? Just wait. If young Wyllis could see what present day Hodor was seeing, that means that Hodor could have known he was going to die all along. That would mean he held the door to protect Bran even knowing that it was going to kill him. Definitely crying now. Hodor was the hero we never knew we had.
It's possible that Hodor did not know he was going to die that day. As we know, Bran's creative time-loop warging caused serious psychological damage to Hodor. So much so that his only word became "hodor," a shortened version of "hold the door," which was to become his purpose in life. Perhaps Hodor didn't realize exactly what this purpose meant. It's possible he didn't realize that holding the door would lead to his death. Or perhaps he knew only that he had to hold the door, and didn't consider the fact that he could also have run away. We do know that Hodor was loyal and protective of Bran right up until the bitter end. Whether or not he knew what was in store for him that night, he is the bravest hero we've seen so far.