The Bible tells us that God uses all for His purpose. This includes how God can use the devil and evil spirits to accomplish what He wants as well.
An event in the Bible gives more light to what this means. A prophet named Micaiah talked to an evil Israelite king named Ahab.
"Micaiah said, 'Therefore, hear the word of the Lord. I saw the Lord sitting on His throne, and all the host of heaven standing by Him on His right and on His left. The Lord said, "Who will entice Ahab to go up and fall at Ramoth-gilead?" And one said this while another said that. Then a spirit came forward and stood before the Lord and said, "I will entice him." The Lord said to him, "How?" And he said, "I will go out and be a deceiving spirit in the mouth of all his prophets." Then He said, "You are to entice him and also prevail. Go and do so." Now therefore, behold, the Lord has put a deceiving spirit in the mouth of all these your prophets; and the Lord has proclaimed disaster against you.'" (1 Kings 22:19-23)
From this event, we know that God holds a council in heaven, and He hears the opinions of angels and hosts. God considers what they say and the effects of all possibilities. Evil spirits and the devil also enter heaven before God's council, as is shown through Micaiah and in Job's case (Job 1:6).
Evil spirits offered to deceive (in Micaiah's case) or to destroy (in Job's case).
We know that God allowed the devil to do what he did in Job's case in order to test Job. But there is more to it than that. Even though Job was tested to the extreme, he was found to be faithful. God used Job's suffering to teach billions of people to trust God in difficult circumstances. Job's suffering resulted in a legacy that lasts forever. Job is honored forever as the one who helps billions of God's followers learn from him.
---
It is not that God puts evil spirits on people to make them sin. But it is true that people already have sin and open themselves up for the work of evil spirits.
We see from Micaiah's case that Ahab was already evil, and God wanted to destroy Ahab through battle. So God used an evil spirit, who deceived Ahab. The false prophets who prophesied in Ahab's favor were also already evil, because they were prophesying falsely in God's name. They even tried to tell Micaiah what to say (1 Kings 22:13). So the deceiving spirit worked in their mouths because of their sin.
It is sin that opens people up for the work of evil spirits.
This was also the case with Saul. "Then Saul became very angry, for this saying displeased him; and he said, 'They have ascribed to David ten thousands, but to me they have ascribed thousands. Now what more can he have but the kingdom?' Saul looked at David with suspicion from that day on" (1 Samuel 18:8-9). The sins of anger, wrath, and jealousy grew in Saul so that he opened himself up for the work of an evil spirit.
This evil spirit was permitted by God in the same way God permitted the evil spirit in Micaiah's case.
It was Saul's sins that caused this. And God used an evil spirit to begin to dethrone Saul. Saul started raving in the midst of the house (1 Samuel 18:10). Other court officials probably saw this and realized that Saul was no longer fit to be king. So through this event, God's purpose could later be accomplished to establish David as king. Most importantly, this paved the way for the Messiah Jesus to be the Son of David.
The Bible tells us: "Be angry, and yet do not sin; do not let the sun go down on your anger, and do not give the devil an opportunity" (Ephesians 4:27). Saul gave the devil an opportunity when he sinned and became violently angry.
---
The Bible tells us that God softens hearts and God hardens hearts. God creates and God destroys. Since God is God, He is able to do all these things. However, it is a person's inclination of the heart that matters most regarding that person's salvation.
Let's look at an example of what this means. We know that during the time of Moses, Pharaoh was not inclined to let the Israelites go. God hardened Pharaoh's heart, but Pharaoh also hardened his own heart (Exodus 8:15, Exodus 8:32). Before the plagues started, God stated that "Pharaoh’s heart is stubborn" (Exodus 7:14). So Pharaoh was never inclined to let the people go. The inclination of Pharaoh's heart was originally unwilling.
The Bible does not say that God hardened Pharaoh's magicians' hearts. During the plague of gnats, the magicians recognized God being at work. "The magicians tried with their secret arts to bring forth gnats, but they could not; so there were gnats on man and beast. Then the magicians said to Pharaoh, 'This is the finger of God.'" (Exodus 8:18-18)
However, it is doubtful the magicians all repented from their wickedness and believed in God. So here are some people whose hearts God did not harden, but they still did not repent even though they recognized God at work.
As can be seen, when God hardens a person's heart, it is not to force that person to disbelieve. Rather, it is to speed up God's purpose. God's purpose was for the Israelites to be free. But Pharaoh would have gone back and forth, taking perhaps years of playing a game of relenting and false repentance, letting the people go for a little while and then trying to bring them back.
So God sped up this process by hardening Pharaoh's heart to the point that he finally let them go due to the severity of the plagues.
Note that God did not put plagues on Pharaoh without fair warning. And God only put plagues on Pharaoh after he refused to listen. God hardened Pharaoh's heart so that he would not go back and forth in lip-service repentance, in which case it would take years for all this process of letting the people go. But God hardened Pharaoh's heart so that things would progress quickly, given that God knew Pharaoh would not truly repent (Exodus 7:14).
So the inclination of a person's heart matters. This is free will. If God hardens a person's heart, it is to accomplish God's greater purpose or to speed up a process. It is not to turn a person from believing to unbelief.
Jesus said, "All that the Father gives Me will come to Me, and the one who comes to Me I will certainly not cast out." (John 6:37).
God does not cause a person to turn away from Him. It is a person's own sin and the inclination of his own heart that turns him away from God.
---
During Old Testament times, people were taught God's law. Those who broke it faced severe punishments.
To learn more about why sometimes women and children were killed, please see this article:
https://www.gotquestions.org/Canaanites-extermination.html
---
Finally, God is just and merciful.
While there are people who died, the Bible tells us that sometimes people die in order to not see evil.
"The righteous man perishes, and no man takes it to heart;
And devout men are taken away, while no one understands.
For the righteous man is taken away from evil,
He enters into peace;
They rest in their beds,
Each one who walked in his upright way." (Isaiah 57:1-2)
Sometimes good people die so that they do not see war or other atrocities on earth.
While there are children who died, the Bible tells us that children go to heaven.
"Now they were bringing even their babies to Him so that He would touch them; but when the disciples saw it, they began rebuking them. But Jesus called for the little ones, saying, ‘Allow the children to come to Me, and do not forbid them, for the kingdom of God belongs to such as these. Truly I say to you, whoever does not receive the kingdom of God like a child will not enter it at all.'" (Luke 18:15-17)
Since God uses children as role models for entering heaven, children themselves will not be prevented from entering.
We know that all people sin. So there are no true innocents. However, God gives special mercy to children. And God judges righteously.
"Will not the Judge of all the earth do right?" (Genesis 18:25)
"And we know that God causes all things to work together for good to those who love God, to those who are called according to His purpose." (Romans 8:28)