It comes from Matthew 16
15 “But what about you?” Jesus asked. “Who do you say I am?”
16 Simon Peter answered, “You are the Messiah, the Son of the living God.”
17 Jesus replied, “Blessed are you, Simon son of Jonah, for this was not revealed to you by flesh and blood, but by my Father in heaven. 18 And I tell you that you are Peter, and on this rock I will build my church, and the gates of Hades will not overcome it. 19 I will give you the keys of the kingdom of heaven; whatever you bind on earth will be bound in heaven, and whatever you loose on earth will be loosed in heaven.”
[end quote]
So, yes, authority given to St Peter to "bind and loose" in heaven and on earth. How that's supposed to work alongside it being Jesus separating the sheep from the goats is anyone's guess.
The reason this takes place at the "pearly gates" is because the new Jerusalem descending from heaven in Revelation is described as having giant pearls for gates.