Nuclear math 101. What can you afford to lose in the event of a nuclear exchange? What are you willing to sacrifice in order to achieve your objective? What is your objective when nukes are the tool on the table?
In Iran’s case - that’s simple - Glass Israel, reduce the entire country to a smoking wreck. They’re not looking to invade, that would be messy and protracted, so they’ll opt for the simplest solution, nuke all the key pop centres and mil assets and turn Israel into an uninhabitable plot of land. Let’s presume they can pull off a Decapitating Strike, and that Israel can’t respond save for second strike SLCM, first and foremost it assumes the Sub will respond with nukes, which is likely not but 100% the case.
There’s the very real possibility that with Israel no longer in existence the Sub may have orders to head for the first allied port and turn itself over to operations there. If it has a letter of last resort like the UK subs do, it will execute those instructions, which could be either “Nuke the sods that nuked us” or “Act on your own volition” or “Head for nearest friendly water”.
If you wipe out the country that you oppose and the damage to you is limited to a few populated areas but your economy, military and core infrastructures remain intact, that’s a worthwhile trade. You can readily afford the few hundred thousand casualties at most that it would mean to wipe Israel off the map for good as that means you’ve just eliminated your biggest local threat. Nukes are not 100% reliable, and the sub will only have as many as it’s carrying (24 most likely) which it can then throw at Iran, a lot of those will be aimed at military assets as opposed to aiming for maximum civilian destruction.
Even if they did go full jihad and dropped the nukes on civ pop centers - 200KT nukes are unpleasant, but far from the worst available, even in the worst case scenario and one lands dead center of Tehran, you’re looking at max 600k Fatalities. If you’ve managed a decapitating strike against Israel, and managed to wipe out most of their infrastructure in the process, that’s very much “Acceptable losses”
You can rebuild cities and infrastructure, sure you’ve got the small problem of say, one or two key cities being possibly uninhabitable, but your most significant opponent in the region is gone. Iran would very, very willingly pay that price. That assumes that any nukes launched from the sub even landed in critical areas.
Finally, those SLBM’s are essentially the only thing that would head Iran’s way, why? Because America wouldn’t be able to glass Iran, nor would any NATO nuke armed countries, due to potential reprisals from Russia (or much less likely China). So whatever Second Strike capability would likely be the only response Iran sees.
When you look at it like that, Iran may see the nuke option as almost palatable.