"God's ways are fathomless. We can't ultimately comprehend the works of God (cf. Romans 11:33-36). Hymn writer William Cowper said, 'God works in mysterious ways, His wonders to perform.' Why does James die and Peter live? We aren't told the reasons. We know that Jesus promised James' death in Mark 10:39, but we're not told why. Surely the church was praying for James, like Peter, yet he was put to death. John, James' brother, lived to be an old man. Sometimes believers suffer terribly, and sometimes God delivers miraculously (Schreiner, 'God's Inscrutable Sovereignty'). We can't predict the ways of God.
"Sometimes those who would be great parents can't have biological children. Sometimes those who are terrible parents keep having babies. Sometimes God answers prayers for healings, and sometimes he doesn't. Sometimes the wicked prosper while the righteous suffer -- at least for a season (Psalm 73).
"While such trials bring much grief and pain, we must not be angry with God. Trials are not necessarily a sign that he's displeased with us. God calls us to trust him, even when life hurts. His ways are wise, good, and just. And we must remember this: God has given us his Son. God doesn't promise to give us an explanation for everything, but he has given us the promise that changes everything: he will raise us from the dead. We will dwell with him in the new heaven and new earth, where sin and suffering can't touch us. God doesn't everything, but through Christ, God has entered into our suffering, has taken the ultimate injustice at the cross, and has risen triumphantly so that all who call out to him may have eternal life. Latch on to this reality in suffering. Glory is coming. It's not here yet, but keep looking to God in faith. He gave his Son for sinners like us, and soon all suffering will end."
~ Tony Merida, Christ Centered Exposition Commentary: Acts