Before we can answer that, we have to answer why there is suffering in the first place. Suffering is a result of sin. Sin brought death and suffering to all of mankind. So, sin is the result of man’s disobedience, and does not exist because God is unloving or indifferent.
But why does he allow us to continue to suffer? Especially after we have been saved? First, we must turn to Hebrews 12:2 where it states, "Let us fix our eyes on Jesus, the author and perfector of our faith." This tells us that Christ not only creates faith in us, but he also sticks around to complete it. But how does he finish or complete our faith? This is answered in James 1:2-4, "Consider it pure joy, my brothers, whenever you face trials of many kinds, [3] because you know that the testing of your faith develops perseverance. [4] Perseverance must finish its work so that you may be mature and complete, not lacking anything."
How does this verse say our faith is completed? Through “facing trials of many kinds,” which is also “the testing of your faith.” This is suffering. Hebrews said Christ is the finisher of our faith, and James tells us how he finishes our faith – through suffering.
That is why he tells us to "count it all joy" when we go through suffering. This is not saying, "Yay, my mother died. I’m joyful," but rather finding joy because Christ is building up your faith. This is also why we can say, "And we know that in all things God works for the good of those who love him, who have been called according to his purpose." (Romans 8:28). If God didn’t use suffering – we could not say "all things," we could only say, "Only things that don’t cause suffering work together for good."
Application:
When you get a ton of homework, someone dies, you break up with a girl/boy friend, etc., you can KNOW that God is building up your faith, so don’t squander that opportunity to grow. It’d be stupid to go through a huge trial and not learn anything from it.
And when you do go through a rough time, sometimes you can Know what the Bible says ("Count it all joy") but you do not feel like having any joy. That’s okay – all is not lost. You can still pray, "God, I know I am going through this tough situation so that you can grow my faith. James 1:2 says to count it all joy, but I don’t feel like that too much right now. God, help me get to that point where I can count it all joy." Then work on bridging the gap between your head (what you know) and your heart (what you feel).