Joe's analysis is spot on. I went through precisely the same thing with (now 4 year old), and continue to do so. The undesirable behavior changes, but the handling remains the same.
I don't think that the five year olds were necessarily responsible for the hitting behavior. From what I have seen hitting seems to be a pretty natural instinct that kids start exhibiting between two and four years of age. The five years olds in question should have learned better by that age -- my four year old lost control and hit me once in the last six months, and realized his error pretty quickly.
Another set of neighbors has walled off their garden and forbidden their kids from playing with the other kids in the neighborhood -- almost certainly thinking this is a way of protecting their kids from bad influences. I condider this a terrible mistake. It's unspeakably awkward for one thing. Their kids go to kindergarten with children who live a few meters away but are forbidden from playing together after kindergarten. So creepy.
I am firmly convinced that whenever my child plays with certain neighborhood kids he comes home imitating behaviors that I find strongly undesirable. I think of as being like a mind-virus that infected my child with its memes. You can try to protect your kid from viruses by raising them in a bubble, but they will grow up with an undeveloped immune system, will be vulnerable, and will probably resent you for giving them a crappy childhood. Alternatively you can give them the support and care they need to recover from their flu's and colds, and they will grow up stronger, healthier, happier, and more resistant to future viruses.
I'm convinced the same holds for learned bad behaviors. If you have the time and attention to spend on your child, youthful mind-viruses are an opportunity to build up your child's character and ability to cope.
At 2.5 the reasoning and conversation skills are more limited, so you'll have to be more creative in your explanations. When I was having a problem with my son hitting me, I found it was part of an overall problem with coping with frustration, not getting what he wanted, and emotional self control. I know many people who made it to adulthood without learning good coping skills, so keep in mind people have to learn these things. If you aren't good at it yourself, work on it at the same time as you help your child learn it.
So how do you deal with it?
My child's hitting phase started at 3, and came together with extreme willfulness, and was usually a part of a general temper-tantrum and thrashing around. I see these happening as a package often enough, that I assume it's your experience as well. If a stern talking to calms her down and gets the desired results -- well done, no more needed. What if she just escalates though?
When my kid was three, he had a phase where he behaved like a real monster. He had learned responses (like "I'm sorry, I won't do it again") which would get him out of a lecture, but then would repeat the behavior almost immediately. He would stubbornly persist in getting what he wanted regardless of our wishes, and it would often escalate into a temper tantrum where he thrashed around wildly, or would hit us. I had friends visiting from abroad and was quite embarassed, as previously he always been so well behaved. I even got impression he was emotionally manipulating me. Scary stuff.
First I had a chat with my wife about how we should handle it, and what we agreed was acceptable and unacceptable behavior. Then, one Saturday he did something that required correction, and things escalated when he didn't take my needs seriously. So I took him into our bedroom and said "Okay son, we aren't leaving the room until you calm down and we can talk about this". He went through basically all of the coping mechanisms that he had picked up (learned or instinctual) -- hitting, kicking, screaming, trying to schmooz me, insincere apologies. Honestly it sometimes felt like my son had become a little devil.
Side note: I found the insincere apologies really hard to cope with. He'd calm down enough to get out what could pass as a sincere apology -- how could I tell I'd gotten through to him? In the end I went with: "okay, I'm glad you see my point. Now we can go downstairs as soon as we can sit here calmly for five minutes."
I was in that room with him for close to 3 hours before he finally got to the point that he could just be calm and carry on. The next weekend a similar event occurred, but was resolved in less than an hour. By the time a month had passed violent outbursts were more or less a thing of the past. Now violence has essentially disappeared from our relationship.
You can also use consequences to discourage undesired behavior. You can think of the above as a negative consequence for the child, and is in that they aren't getting whatever it is that they were originally after... but I think of it as more of an intervention in coping with stress and frustration. When using consequences please consider the following:
- Never promise a consequence you will not 100% deliver on. So never say stuff like "if you don't stop X, we're going home RIGHT NOW", unless you are completely prepared to go home right now.
- Repetition is key. Brains are neural networks, and repetition carves out paths that then become the most easily accessible ones. So frequent consequences that impact the child more than they impact you are best. You can't substitute intensity for frequency, it isn't effective.
Good luck!