Psalm 51:11 (KJV), Cast me not away from Thy presence; and take not Thy Holy Spirit from me.
David teaches us that God can, indeed, reject us and take His Holy Spirit from us. If we indulge our sins, as King Saul did, God will reject us and take away His Holy Spirit. You need only fret if you are a licentious Christian. If you are worried about losing the Holy Spirit, then you need not worry, for one without the Holy Spirit would not worry about losing Him.
David also teaches us that God alone preserves the Holy Spirit in us, for He is a gift. He is not ours to command; He proclaims Christ to us. So long as you trust Christ and remain regularly repentant, you need not worry about losing the Holy Spirit.
Still, though, if you are grieving over a particular sin like David did here, there is nothing wrong with praying this psalm. God will hear your prayer, as He heard David’s prayer. Only the Holy Spirit leads one to pray such a prayer. Thus, if you pray for the Holy Spirit, you already have Him; rather, He already has you.