Philippians 3:8 is a reference to Paul's zealousness as a Pharisee. He upholds the value of the law in Romans, 2 Timothy 3:16, and other places. In fact, in Acts, the Berean Jews were called "noble" for investigating the Old Testament to see if the Apostles were saying the truth.
Romans 3:1-4:
Then what advantage has the Jew? Or what is the benefit of circumcision? 2 Great in every respect. First of all, that they were entrusted with the oracles of God. 3 What then? If some did not believe, their unbelief will not nullify the faithfulness of God, will it? 4 May it never be! Rather, let God be found true, though every man be found a liar, as it is written,
“That You may be justified in Your words,
And prevail when You are judged.” - NASB95
In this passage, Paul says the Jewish people were greatly blessed because they were entrusted with the oracles of God. This is complete respect for the Torah and all the other Old Testament books.
But he further explains later in the chapter:
31 Do we then nullify the Law through faith? May it never be! On the contrary, we establish the Law. - NASB95
So Paul clearly had deep respect for the law.
But in 2 Timothy 3:16-17 he goes further snd blatantly states that it is directly from the mouth of God and is profitable for all aspects of Christian living:
16 All Scripture is inspired by God and profitable for teaching, for reproof, for correction, for [b]training in righteousness; 17 so that the man of God may be adequate, equipped for every good work. NASB95
So it is apparent Paul was not calling the scriptures "shit" by any means. Paul has deep respect for the Scriptures, as evinced from his own writings.
The context for the passage you recite is:
2 Beware of the dogs, beware of the evil workers, beware of the false circumcision; 3 for we are the true circumcision, who worship in the Spirit of God and glory in Christ Jesus and put no confidence in the flesh, 4 although I myself might have confidence even in the flesh. If anyone else has a mind to put confidence in the flesh, I far more: 5 circumcised the eighth day, of the nation of Israel, of the tribe of Benjamin, a Hebrew of Hebrews; as to the Law, a Pharisee; 6 as to zeal, a persecutor of the church; as to the righteousness which is in the Law, found blameless.
7 But whatever things were gain to me, those things I have counted as loss for the sake of Christ. 8 More than that, I count all things to be loss in view of the surpassing value of knowing Christ Jesus my Lord, for whom I have suffered the loss of all things, and count them but rubbish so that I may gain Christ, 9 and may be found in Him, not having a righteousness of my own derived from the Law, but that which is through faith in Christ, the righteousness which comes from God on the basis of faith, 10 that I may know Him and the power of His resurrection and the fellowship of His sufferings, being conformed to His death; 11 in order that I may attain to the resurrection from the dead. (NASB95)
From the context it is apparent the things he is counting as loss are his accomplishments in Judaism as a zealot and his personal following of the Law. He states "for whom I have suffered the loss of all things," e.g. his status and prominence as a zealot in Judaism. Those things he therefore counts as shit (yes. I realize there are translation wars over how that word is supposed to be translated in the Greek. I believe it is a curse word, but many scholars do not) in relation to knowing Jesus personally.
The axiom is not whether the law is shit, but rather, between personal righteousness and righteousness from God. While Paul was murdering Christians, nobody found blame in him before the Law. But as he states, real righteousness comes from faith in God.
It is for this reason that Paul also calls himself "the chief of sinners" in other passages, e.g.:
12 I thank Christ Jesus our Lord, who has strengthened me, because He considered me faithful, putting me into service, 13 even though I was formerly a blasphemer and a persecutor and a violent aggressor. Yet I was shown mercy because I acted ignorantly in unbelief; 14 and the grace of our Lord was more than abundant, with the faith and love which are found in Christ Jesus. 15 It is a trustworthy statement, deserving full acceptance, that Christ Jesus came into the world to save sinners, among whom I am foremost of all. 16 Yet for this reason I found mercy, so that in me as the foremost, Jesus Christ might demonstrate His perfect patience as an example for those who would believe in Him for eternal life. 17 Now to the King eternal, immortal, invisible, the only God, be honor and glory forever and ever. Amen. - 1 Timothy 1:12-17 NASB95
We see here Paul stating that his persecution of the church was outright wrong and he blasphemed on top of that! So the parallel between this and Romans is that Paul is showing that you can do as best as you can, and check as many boxes as possible, but it doesn't matter because we are all sinners. We all fall short. Even those of us who work really hard at trying to follow all the commands and excel in them in the eyes of others, we still cannot make it in on our own merit.
So this is why it is counted as shit to Paul, because it is ultimately not enough to he saved. And that is why faith in God is the only way to forgiveness.