@Switch Blayde
If I die, my social security number is gone (and I guess can be reassigned).
You guess wrong.
https://www.ssa.gov/history/hfaq.html
Q20: Are Social Security numbers reused after a person dies?
A: No. We do not reassign a Social Security number (SSN) after the number holder's death. Even though we have issued over 453 million SSNs so far, and we assign about 5 and one-half million new numbers a year, the current numbering system will provide us with enough new numbers for several generations into the future with no changes in the numbering system.
How does my wife or heir keep getting the royalties?
Provided they have the details for your KDP account, most likely the same way your wife (in the case of separate bank accounts) or your heir would gain control of your bank accounts. Which in the case of bank accounts, would be to provide the bank with your death certificate and proof that they are the legitimate inheritor.
This should be easy for your wife. A copy of your marriage certificate should suffice.
That's what my mom had to do when my father died.
It would potentially be easier if KDP allows you to specify beneficiaries in the event of your death. My IRA is set up like this. I do not know if Amazon would do this for KDP.