We had cats at the nursing home I worked at in Kansas. We had one who did the exact same thing. Whenever a resident was rapidly declining, that cat would lay right next to them. It was a comfort to both the ones who still had their faculties and to the ones who were lost to dementia or Alzheimer dementia. The only time we ever had a problem with this was when we had a little lady who hated cats. Then we had to fight to keep the cat out of her room.
I also had a cat, Jenny, who died many years ago. She was never a particularly cuddly cat but when he began to die she would not leave my side and if I stopped moving, she was on me. It got to were the last few days I just sat with her and didn't get up unless I had no choice. I would tell her I'll be right back baby girl and she would watch me. She passed away on my lap. No pain, just stopped breathing. For a cat that had not ever been snuggly I considered it a great gift! It seems she needed some comfort too.
Our animals are amazing animals for sure.