In Galatians 2 Paul describes a time when he rebuked Peter (Cephas) publicly:
Galatians 2:11-14 (NIV): When Cephas came to Antioch, I opposed him to his face, because he stood condemned. For before certain men came from James, he used to eat with the Gentiles. But when they arrived, he began to draw back and separate himself from the Gentiles because he was afraid of those who belonged to the circumcision group. The other Jews joined him in his hypocrisy, so that by their hypocrisy even Barnabas was led astray.
When I saw that they were not acting in line with the truth of the gospel, I said to Cephas in front of them all, “You are a Jew, yet you live like a Gentile and not like a Jew. How is it, then, that you force Gentiles to follow Jewish customs?
But Jesus told us in Matthew 18 that we should first confront a fellow believer privately, and only expose the sin publicly if they won't repent.
Matthew 18:15-17 (NIV): If your brother or sister sins, go and point out their fault, just between the two of you. If they listen to you, you have won them over. But if they will not listen, take one or two others along, so that ‘every matter may be established by the testimony of two or three witnesses.’ If they still refuse to listen, tell it to the church; and if they refuse to listen even to the church, treat them as you would a pagan or a tax collector.
Is there anything in either of these passages that would explain why Paul thought it was acceptable to start with a public rebuke?