To say that David's friends perhaps should have known what happened in Psalm 41:4, and it might have changed what was happening in Psalm 41:5, is touching on what seems like a very fine line. After all, Jesus had quite a bit to say about the Pharisees living to be seen, making a show of their righteousness (or perceived righteousness). Jesus was all about living your faith diligently in your heart, not on the street corners.
So how do we gel this with what we see happening here, where David's friends-turned-foes don't seem to know the authenticity of his heart and the earnestness of his repentance? How do we live in such a way that there's no misunderstanding about how turned-toward-God we are while also not making a spectacle of our faith for performance's sake?
What we absolutely cannot say is that David should have made his confession to God in the public square. That is certainly not what we should be talking about. There are confessions that we make to God, and there are confessions that we make to men, and there are reasons that we make these confessions in these ways. What is between our heart and God should never be open for public viewing, unless God leads us on the other side of it to share it as a testimony. Your relationship with God is your relationship with God and no one else.
But the relationship that you have with God ought to change the relationships that you have with others, and it ought to change the relationship that you have with your story. Therefore, the things that you do in private with God - which are the things that you should be doing in private with God - ought to shape the life that you live outside of your prayer closet in such a way that no one would question what might be happening in there.
In other words, the world ought to know that your knees are bruised without ever seeing them.
The world, even your friends, don't have to hear you repent before God, but they should know with absolute certainty, by the character of your being, that you have. There should be no question in their minds that that's the first thing you would do. Whatever happens next after you sin or fall short, your next interaction with those closest to you (especially) ought to occur on the assumption that you have already gotten your heart right with God.
You do this by living with godly character. By speaking freely about the relationship that you have with God, without having to share all of the personal details of it. By being honest, earnest, authentic. By being faithful in small things and showing your diligence every day. By being a person of character.
Think about how you know that a husband and wife are committed to each other and love each other. They likely aren't telling you about all of the little things they do, every conversation they have, every time they are intimate with each other, the raw words that came out in a fight. But they are living together in such a way that you know their love is real, you don't question it, and if anything does come up, your foundational assumption is that they love each other, are committed to one another, and are working for the good of one another.
So it should be when the world looks at us with our God. We don't have to share every detail; we don't have to put our relationship with the Bridegroom on public display. But we should be living in such a way that anyone looking knows our love is real and that the foundational assumption anyone makes about us is that we have committed our hearts wholly to God, even in the moments we've fallen.
For whatever reason, David's friends didn't seem to operate on this assumption. That's how they became his foes.
What about yours?