Verses 21 through 24 give Mormon’s moral of the story in advance. As he sets out to tell the next phase of their story, Mormon notes that there are times when the Lord will chasten even his righteous people. He doesn’t explain why. He spends his efforts on the result, which is that by continuing to have faith, rather than reject God due to life’s difficulties, then God will lift them up in the end. Therefore, he declares that this will be the message: Jehovah “did deliver them, and he did show forth his mighty power unto them.”
But what of the unasked question of why? Mormon doesn’t answer, but Lehi did. Lehi gave a powerful discourse on the nature of and the importance of agency in 2 Nephi Chapter 2. Agency is so important that without it there would be no purpose in the creation of the earth (see 2 Nephi 2:12). Although Lehi laid out the need for agency, his sermon did not highlight the unfortunate consequences of agency. God cannot protect us from another’s agency in action. Agency requires that God maintain a light hand on the affairs of the world. God certainly saves his children, and God can help his children overcome the worldly problems associated with agency, but he cannot act in such a way as to void agency. Should he do so, it would “destroy the wisdom of God and his eternal purposes” (2 Nephi 2:12).
Without perhaps understanding that he was giving such an excellent example, Mormon shows that agency operates at times to the detriment of even the righteous. They are not protected from the world at all times. However, through their faithfulness, God can and does save them.