Hello, Sujan @valli.sujankumar. Very insightful question. On the surface, when you read that “God sent an evil spirit”, or God “curses”, it appears to be a contradiction of His character, when in reality, it is because of the holiness and righteousness of His character that we read of these instances, and many others, in Scripture. However, you must read the circumstances surrounding the incidents and why they happened. Every time it is a result of disobedience, an evil an individual has committed, or rebellion against God’s holiness. God cannot allow such things against Him to go unpunished. In Psalm 51:4, David declares his sin is against God, and God only…meaning that all sin is against God.
In the case of Judges 9:23, you must read the whole story to see what is happening. Abimelech has acted treacherously against his brothers, the sons of Gideon, who rightfully were entitled to rule over Israel. God had used Gideon to rescue Israel from the Midianites. Israel asked Gideon to rule over them, but he declined. When Gideon died, Abimelech, the son of Gideon’s concubine, slaughtered Gideon’s other sons who were children of his wives and legitimately entitled to rule over Israel. So, this is the background to why God sent evil. Abimelech set himself up for God’s judgment.
God, was angered by Abimelech’s treachery and behavior and we read in Judges 9:23 that God sent an evil spirit to stir up strife between Abimelech and the city of Shechem. However, the following verse explains why. It was judgment against Abimelech.
The question arises as to how God can do evil when Scripture says that God does not tempt with evil, nor is He tempted with evil (James 1:13). And, as you pointed out, God is Holy. He is so holy, He could not bear the sin that Christ, His Holy Son, was taking upon Himself on the cross (Mark 15:34). Habakkuk 1:13 says that God is too pure to allow His eyes to look at evil. So, what is the answer?
The story of Job gives us a clue. For whatever reason, Satan still had access to God because we see that He had a conversation in heaven with Satan about Job’s righteousness. Satan challenges God about His faith in Job and GOD ALLOWS Satan to bring evil on Job, but not to the point of death. So, what we see is that God will allow evil as tests of our faithfulness, and in the cases you have pointed out in your question, He allowed evil as judgment. In the Exodus story, God sent plagues to break Pharoah down…why? Because the Egyptians were oppressing God’s chosen people and it was the way God used to set the people free.
God is not arbitrary. If He allows evil, it is for a reason. Perhaps, this commentary on Judges 9:23 will help your understanding.
[Benson Commentary] ;
Jdg 9:23-24: (https://biblehub.com/commentaries/benson/judges/9.htm)
God sent an evil spirit — That is, gave Satan permission to work upon their minds. That the cruelty done to the sons of Jerubbaal, &c. — That is, the punishment of the cruelty. Men may do evil, and think they have profited themselves; may imagine they have strengthened themselves in their wickedness, and are quite secure; that they have procured themselves friends, who will stand by them, and save them: but God can, with the greatest ease, make all the devices of the wicked of none effect; can turn their best contrivances to their ruin, and punish them by those on whom they depended for help and security. The example of Abimelech and the men of Shechem, recorded in this chapter, may assure us, that God will not suffer the murderer to escape even in this world; but will punish him in some grievous manner or other.
God has judged Satan by Christ’s death. But, just as in a court of law, judgment has been pronounced, sentencing has not yet begun. Evil is still in the world, but only for a while until it will be ultimately sentenced. God still allows evil, which is difficult for many to understand. That is where God wants believers to trust His judgment.
I hope this helps your understanding. If not, please continue to ask questions so we can look further into it.