An evil spirit from God tormented Saul as a consequence of his repeated disobedience (1 Samuel 13:1–14; 15:1–35), signaling God's rejection of him as king (1 Samuel 15:26). The spirit troubled Saul intermittently, leading him to seek relief, and David's music temporarily eased his distress (1 Samuel 16:14–23). This torment likely aimed to correct Saul's behavior and convict him of his disobedience.
While not true in every situation, physical pain, the presence of evil spirits, or other hardships can be discipline from God. For those who are in Christ, God is our Father, who does not want us to continue in sin, but instead wishes us to bear the "peaceful fruit of righteousness" (Hebrews 12:7–11; Proverbs 3:11–12). We are often tempted to disassociate unpleasant things and the hand of God, but the Bible makes it clear that He both allows and condones discipline for His children. Hebrews 12:7–13 encourages, "It is for discipline that you have to endure. God is treating you as sons. … he disciplines us for our good, that we may share his holiness. … Therefore lift your drooping hands and strengthen your weak knees, and make straight paths for your feet, so that what is lame may not be put out of joint but rather be healed." Even when hardship is simply the natural result of living in a fallen world, we can trust that God certainly uses every circumstance for the sanctification and ultimate good of His followers (Romans 8:28–30). In Saul's case, the evil spirit seems to have been an act of discipline.