In thousands of movies, books and TV shows, vampires have to be invited inside of the house in order to attack the inhabitants. My question is why do they have to be invited inside, is there an actual reason or is this going on ancient folklore? Is there an explanation?
It depends on what vampire literature you're reading.
Much literature decides to use this trope, but some do not. The reasons vary though.
Going back in various mythologies is the idea that supernatural beings — such as vampires, ghosts, demons, witches, what have you — cannot enter into a home unless invited to do so. Often such beings will try to gain entrance by tricking a person into believing they are someone else.
Invitation is a weakness of vampires and hybrids, including Original vampires/hybrids. In order to enter any house owned by humans, witches, werewolves, or doppelgängers, vampires or hybrids must be invited by the owners of the home. Once invited, the vampire cannot be uninvited unless the ownership of the house changes.
In The Vampire Diaries, vampires were not created by the planet compared to the other species. As a defense, nature attacks the vampires with sunlight, wood, vervain, and other elements (for example, water weakens vampires in the books). With the purpose to defend against the undead, the living kept the vampires away by banning them entry into their homes. Literally, it's like saying: I invite my own death to my home.
Entry to homes: Vampires cannot enter private human homes unless they are invited in by the owner of the house. Vampires do not need to be invited into public places (such as bars or restaurants). Humans can rescind their invitations from vampires, which causes the vampire to immediately leave the house. Vampires can get around this by glamouring a person into inviting them in. Ancient vampires might not be subjected to this weakness, suggested by Bill who drank Lillith's whole remaining blood and Warlow that has never been invited to Sookie's house.The death of the human owner of a residence allows any vampire to enter even without an invitation.
Some traditions also hold that a vampire cannot enter a house unless invited by the owner, although after the first invitation they can come and go as they please. Though folkloric vampires were believed to be more active at night, they were not generally considered vulnerable to sunlight
The reasons being (from the sources):
- Protection for humans (that was contingent on their creation)
- It is sometimes not just for vampires, but for other supernatural creatures as well.