Bear in mind that Paul is speaking to the Jews in these quoted texts.
Before we can address the Jewish question, however, I think it is important to share that I think your question reveals a subtle misunderstanding about the grammar in Paul’s letters. You ask: “Was Paul contradicting himself or is there a reason he says you are justified by doing the law then turns around and says we are justified apart from the law?”
As you point out, what Paul says specifically is “…but the doers of the law who will be justified.” This might seem equivocal with your rephrasing “you are justified by doing the law,” but that is not the case. What Paul is saying is that those who are justified will necessarily have been doers of the law, because nobody justified would be conscious doers of anything but the law.
In your second proposition, “…then turns around and says we are justified apart from the law”, you accidentally fuse two separate clauses you provide, one from Romans 3 and the other from Galatians 3. In Romans 3, Paul does not state we are justified apart from the law. He states that the righteousness of God has been manifested apart from the law. Meaning that God’s righteousness is not the law itself, but is above the law and informs his judgment, as the law and God’s judgment both proceed from His righteousness.
In Galatians 3, Paul states that nobody is justified before God by the law. This is in fact qualitatively different from both of his statements in Romans 2 and Romans 3. What Paul is stating in Galatians 3 is that having the law does not justify you. He’s not talking about doing the law, but merely having it.
This is important to understand in the context of the fact that Paul is speaking to the Jews. The Jews thought themselves justified because they had the law, and that gentiles were not justified because they did not have the law. Thus, Paul was chastising them by stating that having/inheriting/upholding the law does nothing: you must do the law if you are truly faithful.
This is why in Romans 2:13, he states also “For it is not the hearers of the law who are righteous before God…” He’s telling the Jews A) that being the bearers of the law does not make them righteous and B) shouting the laws at others does nothing to bring others to righteousness.
To put this in context, one need only read the previous and succeeding verses: “For all who have sinned without the law will also perish without the law, and all who have sinned under the law will be judged by the law… For when Gentiles, who do not have the law, by nature do what the law requires, they are a law to themselves, even though they do not have the law. They show that the work of the law is written on their hearts, while their conscience also bears witness, and their conflicting thoughts accuse or even excuse them on that day when, according to my gospel, God judges the secrets of men by Christ Jesus.”
Paul is telling the Jews, “Look, the sinner will perish whether he has been brought up in the law or not (Jew), and guy who does the right thing has God written on his heart, even if he has never known the law (Gentile).”