If you are speaking within the context of the Judeo-Christian tradition, let me answer right off that the Bible does not teach that God created hell.
This question is part and parcel of the branch of theology called theodicy, which explores the philosophical or logical problem of the existence of evil, which is a paradox hard to resolve. The best biblical exponent of the problem is found in the book of Job.
In the Judeo-Christian tradition, there is no complete answer. As Jesus says in the gospel "No one has seen the Father but the Son" (John 6:46), which teaches that even believers do not know really know all there is to be known about God. We just have been told the little bit we need to know for our own good.
As to hell, it was adopted by Christians of the 2nd or 3rd century from a few verses in which Jesus or others make reference to the Greek idea of Hades. The Hebrew Gehenna or Sheol is not Hell.
The modern theological answer is that God did not make hell, we did. No one goes to hell, strictly speaking; rather, we make ourselves unfit for heaven.
This is a repost from my replies to questions posted on Quora, a question-and-answer site where questions are asked, answered, edited and organized by its community of users, at quora.com. The questions in italics and their subtexts are not mine.