these matters have been discussed at length elsewhere.
The point here is that everything blameworthy in the account of Jonah was forgiven: Allah replaced it with good deeds and raised his rank. After emerging from the fish’s belly and repenting, he held a higher rank than before those events occurred. Allah Most High says:
“So be patient with your Lord’s decree, and do not be like the man of the fish when he called out, filled with anguish.”
“Had grace from his Lord not reached him, he would have been cast onto barren ground, condemned.”
“But his Lord chose him and made him one of the righteous.”
This contrasts with his state when the fish swallowed him, for Allah says:
“Then the fish swallowed him while he was blameworthy.”
He thus states that Jonah was blameworthy at that time. A blameworthy person is someone who has done something deserving of blame. The blame therefore applied to that state, not to his state when he was cast onto barren ground, ailing. Thus, after saying:
“There is no deity except You; glory be to You! Indeed, I have been among the wrongdoers,”
his state was more exalted than it had been before those events occurred. What counts is the perfection attained at the end, not what happened at the beginning; deeds are judged by their endings. Allah Most High created the human being and brought him forth from his mother’s womb knowing nothing, then taught him, taking him from deficiency to perfection. It is therefore not permissible to judge a person’s worth by what he did before attaining perfection; rather, he must be judged by his perfected state. In their final state, Jonah—may Allah bless him and grant him peace—and the other prophets are in the most perfect of states.