The psalmist either had a short sighted view of God, an over-inflated sense of his and his people's own righteousness, a limited perspective, all of the above, some of the above mixed together, or an insight into how things are in the real world -- that both the righteous and the unrighteous suffer.
Some suffering comes because we make right choices. MLK called that redemptive.
Some suffering comes because we all breath common air or because other people make poor choices in a world where we breath common air, or because we wore purple on Friday or for some other random or intentional purpose.
Some suffering comes to shape, better, or enrich us.
In any event, we all suffer and no one theological, philosophical, biblical, moral, or scientific explanation can account for all of it.
" All this has come upon us,
though we have not forgotten you,
and we have not been false to your covenant.
Our heart has not turned back,
nor have our steps departed from your way;
yet you have broken us in the place of jackals
and covered us with the shadow of death.
If we had forgotten the name of our God
or spread out our hands to a foreign god,
would not God discover this?
For he knows the secrets of the heart.
Yet for your sake we are killed all the day long;
we are regarded as sheep to be slaughtered."
(Psalm 44:17-22 ESV)