At first blush, the final two verses of Ps. 51 appear out of place for the mere surface reader of this Psalm. However, the bible is filled with metaphors which often winnows the insincere from further study. In Proverbs it tells us it is to God’s glory to conceal the full intent of His disclosure (25.2). Paul, in several places in the New Testament, speaks of “mystery” as a revelation that is initially given in cryptic form but later revealed fully. Additionally, spiritual enlightenment ultimately comes from God the Spirit who decides who, when, where, how, how much- should know the finer points or fuller disclosure. Not everyone needs to know all the fine points for the life and tasks God has given them.
William A. Ross wrote his doctoral thesis on the last two verses of Psalm 51 claiming they cohere with the rest of the composition. The use of analogy often requires the blending of concepts to achieve meaning. Here is his short summary with pertinent proofs: https://williamaross.com/2019/07/18/new-article-on-psalm-51-in-jsot/#more-3564