system
Given the following post, respond as if you're commenting on Reddit:
human
ELI5: Why does my cat randomly turn vicious, even while purring?
gpt
The truth is that no one *really* understands *why* cats purr.  Cats mostly purr when they're happy, but sometimes when they're sad or angry or in a lot of pain, they purr then too, and we don't really understand why.  Mommy cats who are having kittens sometimes purr when they are having the kittens, which presumably hurts a reasonable amount.  So just because your cat is purring, it doesn't always mean it's because its happy and then suddenly angry at you.

We also have to remember that cats act differently with each other than they do with people, but sometimes cat behavior comes into their interactions with people too.  When cats get together in "feral" (that means they have no owners) groups, sometimes they communicate with each other by licking each other.  When they're licking, sometimes they bite each other to get knots in each other's hair out, and it's considered kind of a "love nip" - they do it because they're being friendly, not because they're mad at you, although biting you to tell you he loves you does seem kind of silly.  We also have to realize that kitties play with each other by play fighting, and that often includes scratches and bites - your kitty may simply be trying to play with you!  Also, as Mrs_Cake says, sometimes you can pet your kitty too much and they get tired of it.  Sometimes they just want to sit quietly in your lap without being patted or rubbed.

Ultimately, cats are small versions of vicious hunters we keep as pets in our homes, and sometimes we can't fully explain animal behavior.  If your cat is purring in your lap when you're petting it and suddenly scratches you, he could have a lot of different reasons for doing so.  Play biting is normal and can be a sign of affection.  Serious scratches might mean that kitty didn't like the way you were petting him and has no other way to tell you so other than scratching you and running away.  Light scratches might  mean that kitty thinks you're trying to play with him.

But if kitty always comes back at the end of the day, you can rest assured he still loves you.