David at one point shared how he was having similar thoughts. It seemed like all the wicked people around him were prospering while he wondered what the use in staying holy. But, by the end of his thoughts David figured out why it was important to stick with the Lord.
Truly God is good to Israel,
to those whose hearts are pure.
But as for me, I almost lost my footing.
My feet were slipping, and I was almost gone.
For I envied the proud
when I saw them prosper despite their wickedness.
They seem to live such painless lives;
their bodies are so healthy and strong.
they’re not plagued with problems like everyone else.
They wear pride like a jeweled necklace
and clothe themselves with cruelty.
These fat cats have everything
their hearts could ever wish for!
They scoff and speak only evil;
in their pride they seek to crush others.
They boast against the very heavens,
and their words strut throughout the earth.
And so the people are dismayed and confused,
drinking in all their words.
“What does God know?” they ask.
“Does the Most High even know what’s happening?”
Look at these wicked people—
enjoying a life of ease while their riches multiply.
Did I keep my heart pure for nothing?
Did I keep myself innocent for no reason?
I get nothing but trouble all day long;
every morning brings me pain.
If I had really spoken this way to others,
I would have been a traitor to your people.
So I tried to understand why the wicked prosper.
But what a difficult task it is!
Then I went into your sanctuary, O God,
and I finally understood the destiny of the wicked.
Truly, you put them on a slippery path
and send them sliding over the cliff to destruction.
In an instant they are destroyed,
completely swept away by terrors.
When you arise, O Lord,
you will laugh at their silly ideas
as a person laughs at dreams in the morning.
and I was all torn up inside.
I was so foolish and ignorant—
I must have seemed like a senseless animal to you.
Yet I still belong to you;
you hold my right hand.
You guide me with your counsel,
leading me to a glorious destiny.
Whom have I in heaven but you?
I desire you more than anything on earth.
My health may fail, and my spirit may grow weak,
but God remains the strength of my heart;
he is mine forever.
Those who desert him will perish,
for you destroy those who abandon you.
But as for me, how good it is to be near God!
I have made the Sovereign LORD my shelter,
and I will tell everyone about the wonderful things you do.
Psalm 73 (NLT)