When discussing matters within the Jewish faith, it is logical for Jesus to state that those who uphold the commandments will be saved. However, it is important to understand that "keeping" the commandments goes beyond mere obedience. To "keep" the commandments involves cherishing and preserving them. The individual who "keeps" the commandments not only follows them but also holds them dear and strives to protect them (internally). Some individuals may go through the motions without truly contemplating the commandments' significance. But not David, who composed many Psalms in which he expressed his devotion to the commandments, frequently meditating on them and cherishing God's word.
Similarly, while Gentile believers are not bound by the law, we still hold onto God's word. We contemplate his teachings and protect them in our hearts. Although we are not required to follow every law, we should hold onto them in our hearts and reflect upon them.
The act of cherishing God's word is a marker of one whom God is saving.
With regard to the Jewish context Paul wrote Romans 10, which sometimes we gentile believers miss.
Romans 10:5-13
For Moses writes that the man who practices the righteousness which is based on law shall live by that righteousness. But the righteousness based on faith speaks as follows: “Do not say in your heart, ‘Who will ascend into heaven?’ (that is, to bring Christ down), or ‘Who will descend into the abyss?’ (that is, to bring Christ up from the dead).” But what does it say? “The word is near you, in your mouth and in your heart”—that is, the word of faith which we are preaching, that if you confess with your mouth Jesus as Lord, and believe in your heart that God raised Him from the dead, you will be saved; for with the heart a person believes, resulting in righteousness, and with the mouth he confesses, resulting in salvation. For the Scripture says, “Whoever believes in Him will not be disappointed.” For there is no distinction between Jew and Greek; for the same Lord is Lord of all, abounding in riches for all who call on Him; for “Whoever will call on the name of the Lord will be saved.”
For a long time, I overlooked Paul's interpretation of Deuteronomy 30. He argues that Moses also taught justification by faith. According to Moses, anyone under the law who keeps the word "near you, in your mouth and in your heart" will be declared "justified" by God. This means that Moses was teaching a "righteousness based on faith." Keeping the commandments involves more than just following them; it also involves loving them, meditating on them, talking about them, and safeguarding them in the heart. According to Paul, this is what Israel should have done instead of seeking their own way to find God's declaration of "justified."
Sorry for the long post, but I think this is an important concept that is easy to miss but so very important to understanding our faith.
Within the Christian context, we keep Jesus' commandments in like manner. Not only do we obey Jesus, we love his word, we meditate on what he said, we talk to each other about what he said, and we preserve what he said in our hearts. Jewish believers and Christian believers are united in that aspect of the faith. We love what God said, we meditate on it, and we safeguard it in our hearts.