Sinclair Ferguson in his book, Man Overboard: The Story of Jonah:
We would be foolish to think that anything God ever says or does means that we can treat sin lightly. But, when his children return to him in true evangelical repentance, accepting his chastisements and humbling themeselves before him, they should hang on firmly to the knowledge that God is able to make his name a praise among the nations even on the shoulders of his children’s failures and sins. Nothing will stop him. If need be he will use the devil himself (as indeed he ultimately will) to bring glory to his name, and to fit his own people for their temporary and eternal destinies.
The principle by which God works is that where sin abounds grace super-abounds (Rom. 5:20). It is this super-abundance of grace and wisdom in God which can make our experiences, even in rebellion against him, serviceable in his hands to equip us for the future.