And that is exactly the premise of a wonderful little book titled: “Why do bad things happen to good people”.
God gave us free will as we were made in his image. (I think I read somewhere else that the angels did not have this - though I don’t know of any scriptural basis for it). But with that free will, Eve and then Adam choose wrongly resulting in a sinful nature in mankind.
The other answer is that there can be no good if there is no bad. What is good if there is no bad? How would one know? Since God is perfect he would not create 1/2 of something, but the whole.
The problem is THERE ARE NO GOOD PEOPLE ...LUKE 18:19 Why do you call me good?" Jesus answered. "No one is good--except God alone.