What do you know about kingdoms in the Middle East in the 1st century? I don't know much, but what I've learned is interesting. A city had to be fortified by a wall. This wall kept the intruders out, especially those that would be a danger to the city and its inhabitants. Letting in the wrong people could be disastrous, as the people of Troy found out.
Who decides who gets to come in and who will be denied entry? Ultimately, it's the king. I'm not sure of the whole process; my guess would be that he would leave standing orders as to who could enter and who couldn't. When the king was away, this task of deciding who would enter and who would not falls to the keeper of the keys. Now, the keeper is not deciding based on his own choice, but based on what the king would want.
In the Israelite kingdom, the keeper of the keys became the position that was held by the second in command. I'm can't remember what the official title was, but the type of position would be the same as what Joseph had in the house of the pharaoh. When the king would have to be gone to war or whatever, they couldn't call him up to ask for his decision on things, so they would have to rely on the king's trusted second in command.
When Jesus promised Peter the keys, He was giving him an office. Not only that, but it was an office that required succession. For me, there is a passage in Isaiah that sheds some light on this whole thing.
In chapter 22, God sends Isaiah to Shebna, the steward, to tell him that he will be cast down for the evil he has done. However, notice that it is a necessary office. Therefore, when Shebna is thrust from the office, Eliakim will take his place.
"In that day I will summon my servant, Eliakim son of Hilkiah. I will clothe him with your robe and fasten your sash around him and hand your authority over to him. He will be a father to those who live in Jerusalem and to the house of Judah. I will place on his shoulder the key to the house of David; what he opens no one can shut, and what he shuts no one can open."
I also think of Lord of the Rings sometimes when I am thinking about the office of the pope. In Minas Tirith, the steward and his family ruled the kingdom for many years while the king was away. That always strikes me as the situation that we have here on earth while the King reigns in heaven. It is not that our King is not present, like an earthly king who can't be in two places at once. However, even though Jesus is present, He has left us someone that will be a father to us ("pope" comes from a Greek word meaning "papa" or "father"). Someone who has the authority to definitively make statements about matters of faith and morals; to definitively "open" or "shut" a matter.
To sum up my inadvertent series on the pope:
The pope is infallible, but he is not perfect.
The pope does not make things up on his own, but relies on what is revealed to him by the Father. Also, he is generally not the only one to realize these things, but is the spokesperson for the whole Church, and the one with the authority to settle a question when there is confusion.
The pope's job is to defend the truth, not to make it up.
The pope is not the ultimate head of the Church, Jesus is. The pope is the steward here on earth who has the task of guiding the Church while we wait for Jesus' return.
Wow! That really was the post that I meant to write! I know that I haven't been the best at giving sources, but a great resource is Jesus, Peter and the Keys by Butler, Dahlgren and Hess. I wouldn't say that it's the most fun read ever, but it does all those scholarly things like give references and builds an explanation based sources and all that good stuff.