Yes Peter was confuse and he didn't fully get what Paul was preaching.
Peter realized Paul had received wisdom from God of which he had trouble understanding
2 Peter 3:15-16 King James Version
15 And account that the longsuffering of our Lord is salvation; even as our beloved brother Paul also according to the wisdom given unto him hath written unto you;
16 As also in all his epistles, speaking in them of these things; in which are some things hard to be understood, which they that are unlearned and unstable wrest, as they do also the other scriptures, unto their own destruction.
...
You can understand better Peter's frame of mind in Galatians 2, by reading carefully what went down in early Acts all the way to Acts 15
Peter was offering the physical kingdom to the Jews, he was pleading with them to repent and be baptized. But he witnessed how the Jewish leaders kept rejecting the Holy Spirit, even after the Holy Spirit blessed him with signs and wonders
Acts 4
The priests and the captain of the temple guard and the Sadducees came up to Peter and John while they were speaking to the people. 2 They were greatly disturbed because the apostles were teaching the people, proclaiming in Jesus the resurrection of the dead.
8
Then Peter, filled with the Holy Spirit, said to them: “Rulers and elders of the people! 9 If we are being called to account today for an act of kindness shown to a man who was lame and are being asked how he was healed, 10 then know this, you and all the people of Israel: It is by the name of Jesus Christ of Nazareth,
whom you crucified but whom God raised from the dead, that this man stands before you healed.
16 “What are we going to do with these men?” they asked.
“Everyone living in Jerusalem knows they have performed a notable sign, and we cannot deny it. 17 But to stop this thing from spreading any further among the people, we must warn them to speak no longer to anyone in this name.”
Peter witnessed for himself how, despite the Holy Spirit giving them signs and wonders to verify their message to the Jewish nation, the leaders are determined to reject God. Peter also knew what happened to Stephen in Acts 6 and 7
8
Now Stephen, a man full of God’s grace and power, performed great wonders and signs among the people. 9 Opposition arose, however, from
members of the Synagogue of the Freedmen (as it was called)—Jews of Cyrene and Alexandria as well as the provinces of Cilicia and Asia—who began to argue with Stephen. 10
But they could not stand up against the wisdom the Spirit gave him as he spoke.
15 All who were sitting in the Sanhedrin looked intently at Stephen, and they saw that his face was like the face of an angel.
Acts 7
54
When the members of the Sanhedrin heard this, they were furious and gnashed their teeth at him. 55 But
Stephen, full of the Holy Spirit, looked up to heaven and saw the glory of God, and Jesus standing at the right hand of God. 56 “Look,” he said, “I see heaven open and the Son of Man standing at the right hand of God.”
57
At this they covered their ears and, yelling at the top of their voices, they all rushed at him, 58 dragged him out of the city and began to stone him. Meanwhile, the witnesses laid their coats at the feet of a young man named Saul.
====
When Peter heard of this account, I strongly suspect he sensed that the Jewish nation is determined to reject what the Holy Spirit is doing in Israel through them. The Great Commission that Jesus gave them in Matthew 28 was not going to be fulfilled, the Jewish leaders are committing the blasphemy of the Holy Spirit by rejecting their message, which under the Law of Moses, was an unforgivable sin.
By the time Peter witnessed in Acts 10 that God is granting the Gentiles the Holy Spirit, indicating that God is now saving Gentiles without them having to do what Peter believed must be done in Acts 2:38, that is to repent and be baptized, Peter could sense that God is phasing out the Kingdom gospel to usher in a new program, which we now know as the Gospel of Grace.
When we come to the Jerusalem Council in Acts 15, Peter remembered what he witnessed in Acts 10, and proposed in vs 11 that from now on, the Jews are to be saved by grace, even as the Gentiles are, that means without the Law of Moses
11 But we believe that through the grace of the Lord Jesus Christ we shall be saved, even as they.
A literal reading will tell you that Peter is actually saying that he wants the Jews (we), from then on, to be saved, as a Gentile (they).
This is very significant because under the Law of Moses, Gentiles could be saved, but only as a Jew. Exodus 12:48 sums that up well.
And when a stranger shall sojourn with thee, and will keep the passover to the LORD, let all his males be circumcised, and then let him come near and keep it; and he shall be as one that is born in the land: for no uncircumcised person shall eat thereof.
So when Peter announced that, it was of huge significance to all the Jews who heard him during the Council.
But alas, Peter could not get that proposal pass James, who was acknowledged to be the head of Jerusalem HQ. James intervened before it could take root, and he did his final announcement that
19 Wherefore my sentence is, that we trouble not them, which from among the Gentiles are turned to God:
James, in my reading, deftly changed Peter's proclamation about how Jews and Gentiles are now to turn to God, into just the Gentiles.
And Acts 21 confirmed it, especially in v20
...Thou seest, brother, how many thousands of Jews there are which believe; and they are all zealous of the law
To conclude, Peter after Acts 15, believed in his heart that God is setting the Law of Moses apart from all, so in Galatians 2, he felt free to behave like a Gentiles. However, when the men from James came, he had to separate himself from the Gentiles because Acts 15 only excused the Gentiles from the Law of Moses.
This explains his behavior in Galatians 2.