Please note that this is about domestic cats which changes the answer slightly. Perhaps the first reason why domestic cats might attack humans is because they are not fully socialised. If a domestic cat is not fully socialised to people she may be fearful of them and if so, if approached by a person, particularly a stranger, they may strike out in defence. Fearfulness leads to defensiveness which in turn leads to a slap or a bite. This is not a wanton, willing attack by a cat on a person but a defensive action. We have to remind ourselves that domestic cats are much smaller than us. We appear as large potential predators to domestic cats unless they are fully socialised. This affects their behavior and relationship with humans.
Another instance when a domestic cat might attack or appear to attack a person is if they are being petted too vigourously by their owner or another person. Over-petting can stimulate a play impulse in an adult domestic cat. When domestic cats play, particular kittens, they roughhouse and play quite hard which includes biting. It can hurt and sometimes domestic as don’t know the limits of how hard they should play. In these circumstances a domestic cat might hold onto a person’s hand with their forelegs and rake the hand with their hind claws. The more the person struggles, the worse it gets. The best solution is to distract the cat with the free hand and remove the trapped hand slowly and gently.
If a person approaches a fully socialised domestic cat in a public area, and the cat does not know the person he may be fearful of them. If the person insists on approaching and trying to pet the animal they may strike and attack the person. The attack will be accompanied by a viscious hiss.
Probably related to @catturd2
Cat don’t take no shit..
— Gorilla Warfare (@RightTheTorch) October 18, 2019
If a person is aggressive towards a cat such as throwing something at a stray cat to get rid of him or her and persist in doing this, the cat might strike back under exceptional circumstances. I remember seeing a woman kicking snow into the face of a stray cat, or it may have been a neighbour’s cat. She did this persistently until the cat lost his cool completely and lept at her face from the ground. He slapped and bit her face. She screamed in shock, horror and pain. She walked inside her home distressed. This is what can happen if you are aggressive without cause towards a domestic cat!
Exceptionally, picking up a cat who is injured or ill may cause the cat to strike out because the human action caused the cat to feel pain. The cat might perceive this as being attacked by their owner and therefore they return the favour.
Transferred aggression is another reason why a domestic cat might attack their owner or another person. This happens when the cat is wound up by something that might have happened outside. The cat wanted to attack another cat or animal but was too fearful to do so and ran inside. The cat encounters their kindly owner and in a moment of mad impulse bites their lower leg to release the desire to attack which has not been fulfilled. This rarely happens and it looks like a wanton act of aggression but it is not.
It would be highly irregular and exceptional for a domestic cat to wantonly and willingly attack a person without apparent reason. This is because the human is not a prey animal for the domestic cat. Therefore, we have to conclude, that the only reason, other than play induced biting, why a domestic cat attacks a person is because it is a defensive action.
I have written this without reference to any information so if I’ve forgotten something please tell me in a comment.