He built a world in which sin would come to pass on purpose.
He could have built a world in which sin would not come to pass if he wanted to.
Without sin there is no Lamb of God receiving forever the praises of a multitude which no man can number of redeemed people from every tribe, nation, kindred and tongue on earth.
Jonathan Edwards said it best:
God may hate a thing as it is in itself, and considered simply as evil, and yet . . . it may be his will it should come to pass, considering all consequences. . . . God doesn't will sin as sin or for the sake of anything evil; though it be his pleasure so to order things, that he permitting, sin will come to pass; for the sake of the great good that by his disposal shall be the consequence. His willing to order things so that evil should come to pass, for the sake of the contrary good, is no argument that he doesn't hate evil, as evil: and if so, then it is no reason why he may not reasonably forbid evil as evil, and punish it as such.
He also explained why sin is important:
It is a proper and excellent thing for infinite glory to shine forth; and for the same reason, it is proper that the shining forth of God's glory should be complete; that is, that all parts of his glory should shine forth, that every beauty should be proportionably effulgent, that the beholder may have a proper notion of God. It is not proper that one glory should be exceedingly manifested, and another not at all. . . .
Thus it is necessary, that God's awful majesty, his authority and dreadful greatness, justice, and holiness, should be manifested. But this could not be, unless sin and punishment had been decreed; so that the shining forth of God's glory would be very imperfect, both because these parts of divine glory would not shine forth as the others do, and also the glory of his goodness, love, and holiness would be faint without them; nay, they could scarcely shine forth at all.
If it were not right that God should decree and permit and punish sin, there could be no manifestation of God's holiness in hatred of sin, or in showing any preference, in his providence, of godliness before it. There would be no manifestation of God's grace or true goodness, if there was no sin to be pardoned, no misery to be saved from. How much happiness soever he bestowed, his goodness would not be so much prized and admired. . . .
So evil is necessary, in order to the highest happiness of the creature, and the completeness of that communication of God, for which he made the world; because the creature's happiness consists in the knowledge of God, and the sense of his love. And if the knowledge of him be imperfect, the happiness of the creature must be proportionably imperfect.