Peter was to be entrusted with the keys of the Church, or rather, he was entrusted with the keys of heaven; to him would be committed the whole people of God. The Lord told him: Whatever you bind on earth shall be bound in heaven, and whatever you loose on earth shall be loosed in heaven.
Now Peter was inclined to be severe, so if he had also been impeccable what forbearance would he have shown toward those he instructed? His falling into sin was thus a providential grace to teach him from experience to deal kindly with others.
Just think who it was whom God permitted to fall into sin—Peter himself, the head of the apostles, the firm foundation, the unbreakable rock, the most important member of the Church, the safe harbor, the strong tower; Peter, who had said to Christ, Even if I have to die with you I will never deny you; Peter, who by divine revelation had confessed the truth: You are the Christ, the Son of the living God.
The gospel relates that on the night that Christ was betrayed Peter went indoors and was standing by the fire warming himself when a girl accosted him: You too were with that man yesterday, she said. But Peter answered: I do not know the man...
Again the girl said to him: You too were with that man yesterday. Again he answered: I have no idea what man you mean…
A third time she repeated: You too were with that man yesterday, but a third time he denied it. Finally Jesus looked at him, reminding him of his previous assertion. Peter understood, repented of his sin, and began to weep. Mercifully, however, Jesus forgave him his sin, because he knew that Peter, being a man, was subject to human frailty.
Now, as I said before, the reason God’s plan permitted Peter to sin was because he was to be entrusted with the whole people of God, and sinlessness added to his severity might have made him unforgiving toward his brothers and sisters. He fell into sin so that remembering his own fault and the Lord’s forgiveness, he also might forgive others out of love for them.
This was God’s providential dispensation.
He to whom the Church was to be entrusted, he, the pillar of the churches, the harbor of faith, was allowed to sin; Peter, the teacher of the world, was permitted to sin, so that having been forgiven himself he would be merciful to others.
--Homily by St. John Chrysostom (d.407)