Full Idea
In his early writings the principle of sufficient reason made it difficult for Leibniz to conceive of possible things;...raising this to possible worlds means God does not choose things that are evil, but chooses a world which must have evil in it.
Gist of Idea
Leibniz proposed possible worlds, because they might be evil, where God would not create evil things
Source
report of Gottfried Leibniz (works [1690]) by Matthew Stewart - The Courtier and the Heretic Ch.14
Book Reference
Stewart,Matthew: 'The Courtier and the Heretic' [Yale 2007], p.238
A Reaction
Where we think of possible worlds as explanations for conditional and counterfactual truths (I take it), Leibniz developed the original idea as part of his huge effort to achieve a consistent theodicy.