You need to talk to the 5 year old.
Your 5 year old should not have to include and play with the 2 yr old when she has friends over, but at the same time, she needs to be kind and still treat her younger sister with respect. Kindness and consideration don't go out the window just because one has guests over.
That is where you need to direct her in how to do both. Does she have to include little sister? No. But she also cannot slam the door in her face. Can she close the door? Perhaps, but she can also do it in a way that is not offensive to her sister. No snarky "we don't want to play with a baby" comments. Saying, we are going to play with just each other right now. And we need to close the door for privacy, is a much nicer thing than slamming the door in her face and saying "no babies". Right?
That is the approach you want to foster...
Little siblings can be annoying. But, that is where you also play a part, Mom. When your 5 year old has friends over and wants to play without little sister, you need to have something ready to occupy the little one. Go in her room and play with her one on one. What a great way to have one on one time with your youngest!
I have a son and a daughter. 3 years apart. Son has had playdates for years. He is now 14 1/2. He'll have his learner's permit this summer. (EEK!) But through all the years, we have always expected that our son treat his younger sister nicely. And often, surprisingly enough, his friends are more than willing to include her. She is 11 now, and in 6th grade. She plays minecraft right alongside her brother and his friends. They will all sit on the porch and play. Or take "Exploderz" guns and run around in the yard shooting each other with them.
She is a fun kid. They are friends.
Part of it may just be their personalities. Part of it is probably that from the very beginning, not being nice was not an option. Ever. No exceptions. BUT, we never forced our son to play with her, either. But he had to be nice. And if he COULD include her without it interfering in what they were doing, we encouraged it, and he didn't mind it. And neither did his friends.