In addition to the clean litter box and marking of territory, my cat used to shit on my bed due to separation anxiety if I was gone for more than a night or so. The only way I stopped it was keeping my bedroom door shut. When I travel now I’ll fold up the comforter and put it in my living room so he can still sleep on something that smells like me, and he’s chill, and he has yet to shit on the comforter. It’s just something about the bed idk.
I’ll strongly voice my support for the suggestion to take your cat to the vet though.