For nuclear deterrence to work in situations like this, it'd also be preferable to have sufficient conventional capabilities that your leadership isn't decapitated before you even notice it's happening. If the attacker is also nuclear-capable, there's little incentive for second person in the chain of command to kill themselves.
Similarly, if a head of state is killed by poison or other similar means, you could hardly expect nuclear retaliation when their successor later discovers what happened.