This is a Psalm of repentance. True joy is only found in the forgiveness of our sins. When God forgives, He pardons the sin, covers the sin, and removes the guild of sin (the legal guilt and the feeling of guilt).
When we have unconfessed sin, it troubles our mind and can even cause physical sickness. But when we confess, the burden in lifted.
God promises to instruct the forgiven believer and leaned him in the way that he should go.