The concept of the threshold as a barrier to evil is popular in many mythologies, though the Judeo-Christian story of the Passover is probably the most prominent of these. The Hebrews were told to mark the lintel and posts of their doorways, the very definition of the threshold, so that the angel might pass over them.
Often construed as a story about obedience, it nonetheless demonstrates a belief that a building can be consecrated in such a way as to ward away evil. Evil literally cannot cross the barrier into the home. The threshold concept extends further to buildings of a sacred nature, even including temporary structures such as the Jewish Tabernacle, which was only a compartmentalized tent, though its layout was the model for Solomon’s Temple.
So it’s not surprising that vampires have an inability to cross a threshold. Homes in ancient times, and across cultures, were always places of protection. For the Jews and Christians it was Passover, but the Ancient Greeks and Romans held the home as sacred because of the goddess Hestia (Vesta in Roman), the goddess of the hearth (which also has a lintel and post) who protected the home.
There is also at play the idea of the hospitality tradition. The tradition states that travelers were to be welcomed into the home; that they would be protected and provided for. It was against the culture to turn away or violate the trust of travelers in any way (see Odyssey book IX [the Cyclops] and the story of Sodom and Gomorrah for the consequences of betraying hospitality).
The vampire mythos, then, upends this idea. The hospitality that was actually striven for is now betrayed by the vampire. By invitation, expected by hospitality, the vampire can cross the threshold and now bring evil to the inhabitants of the home.
I would wager that the vampire mythology is at least partly responsible for the medieval distrust of travelers, and why hospitality has gone into great decline. No longer are travelers accepted, but reviled as they bring evil with them from faraway places. Travelers no longer deserve protection; people must be protected from them.
It’s also interesting to note that an invitation is generally not limited to specific words. An invitation into someone’s home, for example, is never done so formally by a host saying “I invite you in.” Any gesture or vague words of acceptance inside would do, from a simple hand wave to words such as “Come in,” “Welcome,” etc. So you must take care when answering a knock at the door as the wrong words or gesture can let a vampire cross the threshold without you being any the wiser.