It is pretty clear in the Bible story that the whale swallowing Jonah wasn't meant as a punishment from God, it was God saving him from drowning. So it was actually provision to give him a second chance. The whale itself was the start of Jonah's second chance.