The park situation I think tends to happen commonly. As parents we tell our kids not to talk to strangers and then we expect them to invite them to play with us... ?.. how confusing is that for kids to figure out?! It takes a certain amount of maturity for the kids to be able to differentiate when it is okay and when it is not. What you did was great. If their parents were accessible at the park, I might have asked them (the moms) if it would be okay for them to include my child in the game... It all depends on the ages of the kids.
As far as the dance class situation, I've been witness to such things. It always strikes me as stunningly cold. But I honestly would have to ask WHY they would behave that way. There has to be a reason. Not the sort of reason an ADULT might have probably. Maybe something you are unaware of that happened during class or after or before class, or maybe something totally innocent and nice.. like your daughter suggesting they do something differently (trying to help them), or reminding them of a rule the teacher had said. Kids are notorious for "taking things the wrong way". My own kids do this with each other.. one says, put it on THAT way.. (trying to help) and the other gets mad and yells "I know how to do it!" or "I'm doing it!".. If your daughter is a rule follower (which is good) maybe the other kids don't like the comparisons (if the teacher uses her as an example during class?) and want to exclude her for that reason. Or if they feel like she "told" on them for something... It really could be just about anything, and it could be a SMALL thing. Girls are very "feelings" oriented. So some imagined "slight" on their part might be enough to prompt them to exclude her like that. I would have a private chat (nothing formal.. just a few moments out of earshot of everyone else- including your daughter's ears) with the instructor and ask if she knows of any reason the kids might be upset with your daughter. And just ask her to keep an eye out. And by all means, talk to your daughter. Explain how some kids get their feelings hurt unintentionally sometimes, and then get mad at the person they THINK is the cause.. maybe she did something without even knowing it (completely an innocent thing) that hurt one of their feelings for some reason. Ask her if she can think of anything that might have happened or that she might have done (even on accident) that might have hurt their feelings. You could ask her if she wants to ask one of them, "Did I do something to make you mad at me?" And if so, they'll probably tell her what it was. You can practice role playing this sort of conversation. If they say she did, she can say she's sorry, she didn't mean to _____. Then ask, Can we be friends again? Kids can be quick to forgive and move on... My son has learned quite well, to be quick to apologize when he argues with his little sister. They argue, he realizes they are wasting their playtime, and says.. "can we just be friends again?" and she says, "okay".. (sometimes grudgingly) and 30 seconds later they are back fully involved in whatever imaginary game they were playing before.. all the anger is forgotten. If she is not comfortable asking one of the girls directly, don't push her. Just let her know it is an option. As she matures she will use this skill (weighing her options) to make decisions more readily than just "reacting" to things...
But remind your daughter that there is nothing wrong with her. Maybe her friends were just having a bad day. Maybe even were jealous of her for some reason. But she is still a good friend and person and you love her. Give her a squeeze, and try to move on.
You might be surprised to find that at the next class it is like nothing even happened.. You just never know with kids this age. If they are together on a regular basis, they will have ups and downs just like every other relationship.. and they are learning how relationships work. Try not to build it up too much in your mind. But if things are still strained when you next go to class, talk to the instructor or the parents of the girls to try to figure out what happened.
Just wait until she starts school... it gets more like this every day. I seriously doubt there is anything at all "wrong" with your daughter's abilities with friendships. It is just part of growing up. And at 4, not a lot of kids have very good friends yet. They are just beginning to make those kinds of judgments. They might have kids they play with regularly (usually parent arranged) but that is not the same thing as "friends" of their own. And she will have friends. Plenty of them, I'm sure. She's only 4. Help her learn how to choose good friends, and she will have them.