I like the way Augustine explains this. From Chapter 33 of his book On the Predestination of the Saints, the chapter is titled "It is in the Power of Evil Men to Sin; But to Do This or That by Means of that Wickedness is in God's Power Alone."
"What is the meaning of, "as concerning the gospel, indeed, they are enemies for your sake," but that their enmity wherewith they put Christ to death was, without doubt, as we see, an advantage to the gospel? And he shows that this came about by God's ordering, who knew how to make a good use even of evil things; not that the vessels of wrath might be of advantage to Him, but that by His own good use of them they might be of advantage to the vessels of mercy. For what could be said more plainly than what is actually said, "As concerning the gospel, indeed, they are enemies for your sakes"? It is, therefore, in the power of the wicked to sin; but that in sinning they should do this or that by that wickedness is not in their power, but in God's, who divides the darkness and regulates it; so that hence even what they do contrary to God's will is not fulfilled except it be God's will. We read in the Acts of the Apostles that when the apostles had been sent away by the Jews, and had come to their own friends, and shown them what great things the priests and elders said to them, they all with one consent lifted up their voices to the Lord and said, "Lord, you are God, which hast made heaven, and earth, and the sea, and all things that are therein; who, by the mouth of our father David, your holy servant, hast said, Why did the heathen rage, and the peoples imagine vain things? The kings of the earth stood up, and the princes were gathered together against the Lord, and against His Christ. For in truth, there have assembled together in this city against Your holy child Jesus, whom You have anointed, Herod and Pilate, and the people of Israel, to do whatever Your hand and counsel predestinated to be done." See what is said: "As concerning the gospel, indeed, they are enemies for your sakes." Because God's hand and counsel predestinated such things to be done by the hostile Jews as were necessary for the gospel, for our sakes."
Some more relevant scripture:
Gen_50:20 But as for you, ye thought evil against me; but God meant it unto good, to bring to pass, as it is this day, to save much people alive.
Rom_8:28 And we know that all things work together for good to them that love God, to them who are the called according to his purpose.
For all things are for your sakes, that the abundant grace might through the thanksgiving of many redound to the glory of God. For which cause we faint not; but though our outward man perish, yet the inward man is renewed day by day. For our light affliction, which is but for a moment, worketh for us a far more exceeding and eternal weight of glory; While we look not at the things which are seen, but at the things which are not seen: for the things which are seen are temporal; but the things which are not seen are eternal.
(2Co 4:15-18)
Psa 76:10 Surely the wrath of man shall praise thee: the remainder of wrath shalt thou restrain.
Job_1:21 And said, Naked came I out of my mother's womb, and naked shall I return thither: the LORD gave, and the LORD hath taken away; blessed be the name of the LORD.
Ecc 5:19 Every man also to whom God hath given riches and wealth, and hath given him power to eat thereof, and to take his portion, and to rejoice in his labour; this is the gift of God.
Pro 16:33 The lot is cast into the lap; but the whole disposing thereof is of the LORD.
Isa 45:7 I form light and create darkness, I make well-being and create calamity, I am the LORD, who does all these things.