The way I interpreted, Jimmy totally planned to get away with it. He even said that in reply to the lawyer, "how do you plan to come out of this?", he said "on top, like always".
So he was actually able to get his way, and get just 7 years in prison. Only when he learnt that Kim confessed about Howard he changed his mind, and realized that Kim really went through with "turning herself in first", as he spitefully suggested during their phone call.
He finally, at long last, realized that he had to change and to pay for his crimes, so he threw his deal to the wind owning up to what he did, and clearing Kim. Seven years of prison and a life alone? no, better to die in jail but knowing he did Kim right, and showed her he still cared for her and he was able to owning up to his mistakes.
Also, what a big, gigantic F U to Walter White. A man so consumed by "his pride and ego" (RIP Mike) outed as someone who would have been dead or in jail in a month, had it not been for Saul Goodman guiding him, mentoring him and introducing him to Gus. I don't know how famous Saul's "confession" will become in-universe, but what a way to ruin the legacy of the great, terrible Heisenberg. Screw you Walt, that's payback for being a condescending, uptight asshole when someone asks you about a time machine