What we are seeing here is an example of the limitations of early OT theology. The Hebrews initially believed that God was pretty much the active cause of everything, bad and good. For example, in the Book of Exodus we are told that God
caused Pharaoh’s heart to be hardened. Moreover, Job articulates this kind of sentiment as follows, “Shall we receive good at the hand of God, and shall we not receive evil?” (Job 2:10, RSV). Biblical theology gradually develops a better understanding of the distinction between the passive will of God and the active will of God, but during the time Judges 9:23 and 1Samuel 16:15-16 were written, God was considered to basically have only an active will.
In light of all this, consider the following commentary on 1Samuel 16:15:
“An evil spirit from God,” literally “a spirit of Elohim”, which could be translated as “a divine spirit” or “a supernatural spirit.” This is a Hebrew saying consistent with the conviction that everything comes from God - illness as well as good health. The king’s depression of spirit, however, is interpreted as being due to his no longer having the Lord’s support in his role as king.
- Jose Maria Casciaro, general ed., The Navarre Bible: Joshua - Kings (Scepter Publishers: Princeton, NJ, 2000), 266