This behavior is normal and will continue thru middle school. Kids play together and like each other one minute and hate each other the next. They are learning how to get along.
One thing that you can do is always have an even number of kids at a play date. Threesomes rarely get along. One kid is nearly always left out, especially at this young age.
No need to be mortified. This is normal everyday stuff. It's also an opportunity to talk with your child about how he feels, validate his feeling, and also talk about how the other child felt. do this after you get home and he's calmed down. It was healthy for your son to ask to leave and he was feeling like he didn't want to see this friend again. Later he felt differently. That's OK.
It will take time, months and years, to teach him how to be diplomatic when expressing his feelings. Babies come into this world unsocialized. Even at 3 your son's brain is very immature. He's may not yet be capable of showing empathy. Empathy is a more mature way of feeling.
It's important that he knows that it's OK to feel this way but not OK to purposely hurt another child's feelings. When he does, remove him from the situation and later when he's calm talk with him about what happened. You can stay with the play date but go to the two of them and say something like, "you've hurt his feelings. I want you to say sorry." If he doesn't want to say sorry, take him to another part of the area until he's once more in a good mood.
I suggest that once the two kids started to exclude the other one that if efforts to get them to play together didn't work, that it was time to stop the play date. It's a matter of the parent monitoring and managing the situation because the toddler is unable to act like an adult and be kind to everyone.
This behavior could mean that he needs more attention. I also think it could mean that his feelings need to be validated. It's OK to not want to play with someone. It's OK to not like someone. It's also OK to tell someone that you don't like them and don't want to play with them. How much better relationships would be if we learned at an early age to be honest.
Of course, we then have to deal with the other kids hurt feelings when we say those things. He likely doesn't know how to respond to the tears and is likely to become angry. This is where Mom comes in and says, he's feeling hurt because you don't want to play with him. That's OK. and then separate the two. Let him know it's OK but it's not OK to hit. If you've separated them at the beginning he won't have an opportunity to hit.
We cannot just say, that's not nice. A toddler has no concept of what nice is and their brain is not mature enough to understand how another child feels.