You are no doubt referring to the account in 1st Samuel 16:14-23. Let’s read verses 14-16: “But the Spirit of the LORD departed from Saul, and a distressing spirit from the LORD troubled him. And Saul’s servants said to him, ‘Surely, a distressing spirit from God is troubling you. Let our master now command your servants, who are before you, to seek out a man who is a skillful player on the harp. And it shall be that he will play it with his hand when the distressing spirit from God is upon you, and you shall be well” (NKJV). Before we bring David into the picture, it’s important to see that before the “distressing spirit” (which was indeed a “demon”) came upon Saul, the “Spirit of the LORD departed” from him. I believe the reason for both is the same: God was disciplining Saul for his disobedience (you can read about Saul’s rebellion against God’s word in chapter 15). Because of this, God removed the Holy Spirit from Saul and then He ALLOWED an evil spirit to come upon him to “trouble him.” The “trouble” Saul experienced was some form of depression. Many believe it was what we know today as “manic depressive psychosis,” a severe mental illness. The cause of this illness today may not always be known, but in Saul’s case it was indeed a tormenting spirit (a demon) that created a sense of doom and gloom, which included a paranoia which led Saul to believe people were plotting against him. We want to stress the fact that even though God allowed this to happen as a form of punishment for Saul, the evil spirit gladly participated of his own free will. God ALLOWED Saul to be tormented, but He didn’t DO it.

Now let’s read about David in verses 17-23: “So Saul said to his servants, ‘Provide me now a man who can play well, and bring him to me.’ Then one of his servants answered and said, ‘Look, I have seen a son of Jesse the Bethlehemite, who is skillful in playing…and the LORD is with him.’ Therefore Saul sent messengers to Jesse, and said, ‘Send me your son David, who is with the sheep.’ And Jesse…sent…his son David to Saul. So David came to Saul and stood before him. And he loved him greatly…and became his armorbearer…And so it was, whenever the spirit from God was upon Saul, that David would take a harp and play it with his hand. Then Saul would become refreshed and well, and the distressing spirit would depart from him.” We want to emphasize what Saul’s servants said about David. After stating that he was “skillful in playing,” they added “and the LORD is with him.” This was the “key” to David’s “success in life” and it will be the key to our success as well. Without this key, David would have merely been a talented musician, but he would not have been chosen by God to minister to Saul’s needs. So, in answer to your question, I believe it was “David’s obedience to God” that allowed God to use him to expel the evil spirit, just as it was “Saul’s disobedience to God” that led God to use the evil spirit to punish Saul. This is not to say that the music itself had no value in relieving Saul’s tormented mind, for it did. But it was David’s TALENT, coupled with his David’s DEPENDENCE ON GOD that resulted in God’s power being manifested in the expulsion of the distressing spirit and the healing of Saul’s mind. This should encourage all believers to use whatever talent or spiritual gift we have for God’s glory, for if we do, God will surely use us for His glory and for man’s blessing.  (218.5)  (DO)