What happens to my stake if a validator unregisters / goes offline permanently?

Your staked XRD is safe. You can just request to unstake in the Radix Wallet and your XRD will be unlocked after 500 epochs (about 12 days)

Longer explaination:

When you stake with a validator, a record is written to the Radix ledger that delegates a quantity of XRD to that validator. The staked XRD never leaves your wallet and still belongs to you.

If a validator decides to unregister as a validator, or just stops running the validator node then your stake will no longer receive further staking rewards - but you will not lose any of your staked XRD and the rewards you have already earned.

You will need to unstake from the validator in the Radix Wallet which will write a record to the Radix ledger to unlock the stake from the validator. The unstake operation is part of the Radix protocol and so it can always be performed irrespective of whether your staked validator is running or not.

The unstaking process will take 500 epochs (about 12 days) to unlock and then you will be free to restake with another validator.