This is always a touchy subject because we, as parents, want the best for our children and don't want them to be hurt. Friends are a vital part of our life and we need to teach our young children how to be good friends to all. When they encounter someone whom they cant really do things with, they do wonder why.
The best thing to do is to allow your child first and foremost, to let their feelings out and to ask any questions that they may. It's your job to make sure that they understand that although they may want to get together with the other child, that their parent may not allow that to happen. We need to explain that everyone is raised differently and that some children have restrictions as to when, where and who they can play with. Always make sure that your child understands that its NOT a direct correlation to them as a person so that they don't feel like its their fault that they cant play together.
When my children were small, I too went through this and my daughter couldn't understand why this happened. I explained to her that although we may see the other girl at a party or at a neighborhood get together, her mom didnt want her to have a friend or two over because she was very afraid that if something happened to another child at her home, she would be responsible and she didnt want to worry about that. So she only allowed her daughter to play with friends when all the other parents were around. My daughter understood that and I made sure that she knew it had no reflection as to who my daughter was.
It's tough being a parent at times...