Ponyboy is attacked because he is walking home from the movies alone.
Ponyboy is attacked when walking home from the movies by the Socs because he is a greaser, and the two gangs are engaged in an ongoing retaliatory turfwar. He is vulnerable because he is alone.
Ponyboy explains early on that he should not be walking home alone, because he is a greaser and he risks getting “jumped” or beaten up.
Greasers can't walk alone too much or they'll get jumped, or someone will come by and scream "Greaser!" at them, which doesn't make you feel too hot, if you know what I mean. We get jumped by the Socs. (Ch. 1)
The greasers are the poor kids from the East Side, which means that they wear their hair long and dress in t-shirts and jeans. The Socs are the rich kids, the “jet set” from the West Side. They have the fancy cars and all of the money.
Socs and Greasers are constantly at battle. The issue seems to be one of class (rich and poor) and neighborhood (West and East). It does not matter whether you want to be involved. You are involved regardless, because of where you grow up.
[Socs] jump greasers and wreck houses and throw beer blasts for kicks, and get editorials in the paper for being a public disgrace one day and an asset to society the next.
Pony comments on the behavior that gets greasers into trouble with law.
Greasers are almost like hoods; we steal things and drive old souped-up cars and hold up gas stations and have a gang fight once in a while. (Ch. 1)
Misbehavior from Socs seems to be dismissed as a youthful indiscretion, while from a greaser it can result in a criminal recored. This is a result of the double standard that society has for these young people. Socs have a future, greasers do not.
Like many street gangs, the Socs and greasers identify themselves by fashion. The greasers choose theirs based partially on what they can afford with their working-class background. The Socs naturally have a preppier approach. The greasers are more “hood.”
[We] wear our hair long and dress in blue jeans and T-shirts, or leave our shirttails out and wear leather jackets and tennis shoes or boots. (Ch. 1)
It often seems as if Socs are attacking greasers, and vice versa, because of an endless cycle of violence and revenge. One group attacks the other because of an attack that happened before. What might have started because someone was bored just perpetuates, and no one can stop it.
Pony's brother Soda perhaps says it best, about the reason Pony was attacked.
"Leave my kid brother alone, you hear? It ain't his fault he likes to go to the movies, and it ain't his fault the Socs like to jump us, and if he had been carrying a blade it would have been a good excuse to cut him to ribbons." Ch. 1)
When Ponyboy is attacked, the Socs have nothing in particular against him. They chose him because he was a greaser, their prey, and an easy target because he happened to be alone. There is strength in numbers. They tease him about his hair, saying they will give him a haircut. They know he is a greaser because his hair is long. He did nothing to them.
Later in the book we see examples of philosophical conversations between greasers and Socs about whether or not they want the violence, and the effects of the violence on them, especially when people die. It takes its toll. It definitely is not just innocent fun. Johnny is a mess from the beating he takes. Some of the kids on either side seem to enjoy it, and there is camaraderie in being part of a group, but always looking over your shoulder wondering if you are about to get attacked is no way to live. Innocent people get hurt for no reason.