I don't find it mysterious. I just think that cats are inherently not social, so they only use people to suit their needs at a particular time.
Like when they're getting petted, it might feel nice for a while, then when it suddenly doesn't feel so nice anymore, that's when the scratching starts.
That's why they go to get food from neighbors or anyone else. They don't need the companionship, and only sometimes need the food. It doesn't really matter who supplies the food.
"Why do you scratch and hiss for no reason". What a shitty puzzle. Not a puzzle I'd choose to play.
I suppose some people are gluttons for punishment... or possibly suffering from toxoplasmosis.