David sinned. He followed the way of the righteous when they sin. He confessed his iniquity (gross immorality and injustice) to God and he was troubled with his sin. As David would have read in Leviticus 5:5-6 “When anyone is guilty in any of these ways, he must confess in what way he has sinned and, as a penalty for the sin he has committed, he must bring to the LORD a female lamb or goat from the flock as a sin offering; and the priest shall make atonement for him for his sin.”
When his enemies heard of his confession they took advantage of the situation. Though David had done nothing against them, they vigorously sought his downfall. They hated him without reason. They repaid his good with evil. They slandered his name for pursuing what is good. This is the reason for his prayers at this time. He asked for the Lord God to come to his aid.
David wrote of hate without reason before in 35:19 and 69:4. The Apostle John wrote in his gospel that this was fulfilled in the life of Jesus. (John 15:24-25) When the Bible speaks of hate without reason it does not mean that those who do so do not have self-justifications for their actions. Rather, it means that there is no Godly justification for their hateful actions. Their false justification usually falls under prideful judgment and execution of punishment, almost always as a benefit of self. Most are like in this case. They seek to dispose of their enemy and justify it saying, “They deserve it.”
Jesus taught, “Do not judge, and you will not be judged. Do not condemn, and you will not be condemned. Forgive, and you will be forgiven.” (Luke 6:37) “For in the same way you judge others, you will be judged, and with the measure you use, it will be measured to you.” (Matthew 7:2)