This is a psalm about responding to bad stuff that happens to us, especially continuous bad stuff that happens to good people. God promises that the "rod of the wicked" will not "rest" upon the righteous. Oh, there may be moments -- long moments-- when it looks as if evil has actually found a home in our lives. But the psalmist says that that good people can be tempted too much and they might respond to the rod of the wicked resting upon them by putting their hands out to doing evil. We refrain from doing evil because we continue to trust in God and to not fret ourselves against those who do evil. Psalm 37:1,2
Then the psalmist reminds God to do good to good people. Always good to remind God of stuff, I say.
And once again, the psalmist warns the good person: "If you turn from living a good life just because bad has happened to you, then God sill see no difference between you and the evil person.
Psalm 1251They that trust in the LORD shall be as mount Zion, which cannot be removed, but abideth for ever.
2As the mountains are round about Jerusalem, so the LORD is round about his people from henceforth even for ever.
3For the rod of the wicked shall not rest upon the lot of the righteous; lest the righteous put forth their hands unto iniquity.
4Do good, O LORD, unto those that be good, and to them that are upright in their hearts.
5As for such as turn aside unto their crooked ways, the LORD shall lead them forth with the workers of iniquity: but peace shall be upon Israel.