I was taught you can lose your salvation. Is that true? If not, then why does David ask the Lord in the Psalms to “Cast me not from thy presence oh Lord, take not thy Holy Spirit from me.” He makes it sound as if it is possible for the Holy Spirit to be removed.
The clear, unmistakable and continual teaching of scripture from Genesis to Revelation is this: it is impossible for a saint to ever return to the unregenerate state he existed in prior to faith. In other words, it is impossible to lose your salvation. Once you believe, you become an adopted child of God, never to be sent away again (Eph 1:5; Gal 4:5). You were sealed forever by the Holy Spirit (Eph 4:30).
You were not saved by your actions nor thoughts, but by His will and grace (Eph 2:8). Therefore, if you did nothing to obtain your salvation, you can do nothing to lose it. It was never under your control. It is a gift.
Secondly, you cannot lose your salvation nor even "turn it in" because of what God did in your heart and spirit at the moment of salvation. He performed a permanent work in your spirit by putting the old spirit to death and bringing you a new spirit, so that you are now a new creature (2Cor 5:17). The old self is gone forever never to return. You can no more return to your old state than a butterfly can return to the cocoon and become a caterpillar again. It's not a matter of our will or desire or even our obedience. To return is simply spiritually impossible. Praise the Lord!
Regarding David's comment in Psalm 51, this is a significant psalm for several reasons. I've included a copy of the Psalm below in a modern English translation:
This psalm describes the nature of the salvation process. The psalm begins with David acknowledging his sin before God (vs. 1-5). These verses describe the repentance step of salvation, including the fact that all men are born sinful (v. 5).
Then David moves next to describing spiritual regeneration (vs. 6-10), the time when God changes our hearts and brings us the gift of faith (see also Eph 2:8-9). This is the part of the salvation process where our old nature (i.e., our old spirit) is put to death and we are made a new creature in Christ (v. 10).
Pay close attention to the language of verse 6 in particular, where David describes how God plants wisdom (i.e., brings the knowledge of salvation through the Lord) in a "hidden" part of himself. His sins were blotted out (v. 9), which means they simply don't exist anymore. There is no condemnation possible for a Christian, because the entire penalty for our sins has already been paid by Christ. God can't punish us for sin, because that punishment has already been given to Christ.
Then in vs. 11-15 David expresses the hope of his salvation. David is not wondering if God will do these things; rather, he is acknowledging that these things will be the consequence of God granting him salvation. Look at the full list:
v.11 - the believer is never to be cast away
v.12 - the believer has joy in his salvation and is sustained by God's will
v.13 - the believer then teaches others and converts unbelievers
v.14 - the believer is free from the guilt of sin and praises God's righteousness
v.15 - the believer praises God
These are the consequences for a believer who has obtained salvation. As a new creature in Christ, we have these new behaviors to accompany our new nature. (Please see 1John 2 for a good teaching on this principle.)
Given all David wrote, the only way to interpret v. 11 to mean that a believer can lose salvation is to read that point of view into the text, since the author himself didn't have that thought on his mind when he wrote those verses. In fact, the author's point was completely the opposite - David was declaring the good things that come with salvation.