The lore is basically the story and plot line from beginning to end. This is especially true in role playing games where story is the most important part. You don't think games like Final Fantasy and World of Warcraft would get very far if they didn't have good stories behind them.
Game developers hire writers who know how to craft stories, missions, lore for a game and can make these stories interesting to the player. Anyone that has played a massive multiplayer online role playing game like WOW knows that a good portion of the quests are pretty straight forward. You go here, grab this and go back.
This is because there needs to be plenty of filler quests, but even these small one had someone sit down and develop it. I remember playing Fable Iii and coming across a small quests where I had to woo a wife, so the husband could get a divorce. In the end, I had to choose to kill him and get the girl and the money or do follow along with the deal.
That totally came from the mind of the writer who had been wronged by an ex-girlfriend. Next time you sit down and play a fantasy game, remember that it all came from the mind of a very good writer.