Pretty sure Paul would have known who was who. Yet also demonstrating he had a better knowledge of the law than they did, knew what he was doing and was now living by the Spirit not the law. For Paul, Christ was now the high priest, and it was Ananias speaking against Christ, not Paul speaking against Ananias that was the sin.
1 Paul looked straight at the Sanhedrin and said, “My brothers, I have fulfilled my duty to God in all good conscience to this day.” 2 At this the high priest Ananias ordered those standing near Paul to strike him on the mouth. 3 Then Paul said to him, “God will strike you, you whitewashed wall! You sit there to judge me according to the law, yet you yourself violate the law by commanding that I be struck!”
4 Those who were standing near Paul said, “How dare you insult God’s high priest!”
5 Paul replied, “Brothers, I did not realize that he was the high priest; for it is written: ‘Do not speak evil about the ruler of your people.’”
6 Then Paul, knowing that some of them were Sadducees and the others Pharisees, called out in the Sanhedrin, “My brothers, I am a Pharisee, descended from Pharisees. I stand on trial because of the hope of the resurrection of the dead.”
Hebrews 4:14-16
14 Therefore, since we have a great high priest who has ascended into heaven, Jesus the Son of God, let us hold firmly to the faith we profess. 15 For we do not have a high priest who is unable to empathize with our weaknesses, but we have one who has been tempted in every way, just as we are—yet he did not sin. 16 Let us then approach God’s throne of grace with confidence, so that we may receive mercy and find grace to help us in our time of need.