Our heavenly Father is absolutely, infinitely perfect. He has already created perfect beings in the celestial realms who have freewill and cannot sin. At the same time, in the very same heavenly realms and here in the earthly realms, he created celestial and terrestrial beings who have freewill and can sin.
This allows for all kinds of diverse experiences to occur. New creations, new meanings, values, treasures, beauty, lessons, etc, are realized as a result. Those who can sin are not left helpless. They are given all the tools they need in order to evolve, to climb up to become perfect, even as the glorious heavenly Father himself is perfect.
There are reasons for all these in line with a mind-boggling eternal divine plan and purpose, way, way, way beyond our present abilities to fully comprehend. But please check this out: We can begin to understand it little by little. Hallelujah! Peace be upon you and stupendous tidings of great joy!