Failure is useful in physical development as well. Strategically working a muscle to failure—the point at which you can no longer lift or push or pull whatever you are lifting or pushing or pulling—and then allowing proper time for the muscle fibers to repair is one of the most effective ways to build strength. This process of failing and repairing eventually results in stronger, more efficient muscles.
If failure is important to our intellectual and physical improvement, perhaps it is important in our quest for perfection as well. Could it be that our moments of extremity are necessary for our spiritual progress and that our Savior knows that only then we are ready to learn?
Cassy Budd, "On Failing and Finishing", BYU Speeches, February 14, 2017
When I do strength training (or used to), I would lift to the point of failure. When you strength train to the point of failure, you are tearing the muscle fibers. Your body then goes to work rebuilding those muscles. During this rebuilding process, you feel "sore" because of lactic acid buildup. When all is rebuilt, that muscle is stronger than before.

Now, think about your spiritual muscles. Don't they get stronger in the same way? If we reach the point of failure, do we not get stronger when those spiritual muscles are rebuilt?
Don't we all go through spiritual failures and spiritual muscle tearing at times? Are we not "sore" afterwards, feeling regret and remorse while that rebuilding happens? Then, as the rebuilding and the repentance process are complete, are we not stronger than before?
This process of tearing spiritual muscle fibers and then rebuilding them stronger is the atonement of Jesus Christ.
We know exercise is vital for a long, happy life. But spiritually exercising is crucial for eternal life. Sometimes that exercising requires tearing the muscles, and sometimes just going for a spiritual walk is sufficient.
Opposition is necessary so that we exercise, and the atonement is critical so that we get stronger.