It is important to recognize that the Bible can speak against obeying the Torah for incorrect reasons without speaking against obeying it for corrects and that the correct solution to doing something incorrectly is to start doing it correctly rather than to cease doing it. For example, in Matthew 23:23, Jesus said that tithing was something that they ought to be doing while not neglecting weightier matters of the Torah of justice, mercy, and faith, so he was not opposing their focus on obeying the Torah, but rather he was calling them to have a higher level of obedience to it in a manner that it is in accordance with its weightier matters.
Those verses should not be interpreted in a way that contradicts Matthew 7:21-23, but a way that is informed by it, so it does not work to interpret those verses as saying that focusing on the Torah is worthless and we should focus on knowing Christ instead when Christ said that he would tell those who are workers of lawlessness to depart from him because he never knew them.
God's way is the way to know Him by being a doer of His character traits, such as in Genesis 18:19, God knew Abraham that he would teach his children and those of his household to walk ini God's way by being a doer of righteousness and justice that the Lord might bring to him all that He has promised. In Exodus 33:13, Moses wanted God to be gracious to him by teaching him to walk in His way that he and Israel might know Him, and in 1 Kings 2:1-3, God taught how to walk in His way through the Torah. In Jeremiah 9:3 and 9:6, they did not know God and refused to know Him because in 9:13, they had forsaken the Torah while in 9:24, those who know God know that He delights in being a doer of steadfast love, justice, and righteousness in all of the earth, so delighting in being a doer of God's character traits in obedience to the Torah is the way to know Him. Moreover, this is also the way to know the Son, who is the radiance of God's glory and the exact likeness of God's character (Hebrews 1:3), which he expressed through his actions by setting a sinless example for us to follow of how to walk in obedience to the Torah. In 1 John 2:4, those who say that they knew Jesus, but don't obey his commands are liars, and in 1 John 3:4-6, those who continue to practice sin in transgression of the Torah have neither seen nor know Him. So the goal of the Torah is to teach us how to know God and Jesus by being a doer of His character traits, which is eternal life (John 17:3).
The issue is that someone can go through the motions of obeying the Torah while neglecting to be a doer of the character traits that it was given as a gift to teach us how to express, such as in Matthew 23:23. In John 5:39-40, Jesus said that they searched the Scriptures because in them they think that they will find eternal life, and they testify about him, yet they refuse to come to him that they might have life. In Luke 10:25-28, Jesus affirmed that obedience to the greatest two commandments of the Torah is the way to inherit eternal life, so eternal life can be found in the Scriptures and they were correct to search for it there, but they needed to recognize that the goal of everything in Scripture is to testify about how to know him through being a doer of His character traits, which is the way to eternal life. In Romans 9:30-10:4, they had a zeal for God, but it was not based on knowing Him, so they failed to attain righteousness because they misunderstood the goal of the Torah by pursuing it as through righteousness were earned as the result of their works in order to establish their own instead of pursing it as through faith in Christ, for knowing Christ is the goal of the Torah for righteousness for everyone who has faith. In Philippians 3:1-9, Paul was in the same situation where he had been zealous for the Torah, but he had neglected to know Jesus through being a doer His character traits, so he had been missing the whole goal of the Torah and that is what he counted as rubbish.