@SW-User
It's because God created this world and the people in it.
I think if God had wanted a world without pain and misery, a good way to approach that would be by not letting people have "free will". Clearly, God can tolerate our suffering because he chose for us to have free will.
This free will is in most cases why people choose to do bad. Of course that doesn't really answer why some people have to get ill or die in accidents, but you could argue that a lot less of us would have problems if we all did fellow the Mitzvot (commandments) and sought to do what God wants.
What good is free will if you will be punished for the actions of others?
Exodus 20:5 (TLB) = "5 You must never bow or worship it in any way; for I, the Lord your God, am very possessive. I will not share your affection with any other god!
“And when I punish people for their sins, the punishment continues upon the children, grandchildren, and great-grandchildren of those who hate me;"
Exodus 34:7 (TLB) ="7 I, Jehovah, show this steadfast love to many thousands by forgiving their sins;[a] or else* I refuse to clear the guilty, and require that a father’s sins be punished in the sons and grandsons, and even later generations.”
Numbers 14:17-18 (TLB) = 17-18 “Oh, please, show the great power of your patience[a] by forgiving our sins and showing us your steadfast love. Forgive us, even though you have said that you don’t let sin go unpunished, and that you punish the father’s fault in the children to the third and fourth generation."
Deuteronomy 23:2 (TLB) = "2 A bastard may not enter the sanctuary, nor any of his descendants for ten generations."
Isaiah 14:21 (TLB) = "21 Slay the children of this sinner. Do not let them rise and conquer the land nor rebuild the cities of the world."
Genesis 9:21-25 (TLB) = "20-21 Noah became a farmer and planted a vineyard, and he made wine. One day as he was drunk and lay naked in his tent, 22 Ham, the father of Canaan, saw his father’s nakedness and went outside and told his two brothers. 23 Then Shem and Japheth took a robe and held it over their shoulders and, walking backwards into the tent, let it fall across their father to cover his nakedness as they looked the other way. 24-25 When Noah awoke from his drunken stupor, and learned what had happened and what Ham, his younger son, had done, he cursed Ham’s descendants:[a]
“A curse upon the Canaanites,” he swore.
“May they be the lowest of slaves
To the descendants of Shem and Japheth.”
There are lots of other such passages. So, even if you are good you will be punished for the sins of your ancestors and even killed, if you are a baby.