When we write, the scenes and chapters we produce have different combinations of characters in them that work to advance the plot. Those characters might start a scene already grouped together, but it is also often the case that they do not, and one or more has to enter. Others might need to leave later on. The entries and exits of characters need to be tightly controlled by you as an author if you are to avoid potential problems. Here are some of the things I think you absolutely have to consider:
1. Who is going to be needed in the chapter? If you can work it out ahead of time, then it becomes much easier to have all the characters around, rather than trying to introduce them at odd points. Are particular characters needed to perform particular actions? Could they conceivably be done by others?
2. Have a good reason for arriving/leaving. People do not go to see one another without a reason (and ‘seeing someone socially’ counts as a reason) so make sure that your characters do. They might need to talk urgently, or might be visiting, or might even genuinely need a cup of sugar. The point is that they need to show up for a better reason than ‘I’m the author and I need them there’ and leave for another reason, even if it’s just that they’re bored with talking.
3. Make sure that they can get there. I once heard that British soap opera Eastenders times journeys across its square so that characters don’t just jump from location to location. If true, it’s certainly fun, and highlights an important point. Unless you’re writing sci fi, your characters probably aren’t teleporting everywhere, so the character who was in Scotland one minute should not show up in Wales the next.
4. Asides should be rare. In fiction of a certain kind, people always seem to be pulling one another to one side. Now, I’d like you to imagine what you would do if someone butted into the middle of a conversation you were having with someone and took them away so you could not hear what was being said. Unless it was in a context where secrets were normal, you would be curious, wouldn’t you? You might even be a little offended at being excluded like that. So shouldn’t your characters be? Again, this is a device for the author rather than something coming out of the character’s behaviour.
5. How do they know where they are? A variation on point three. If your main character has wandered into the middle of a safari park a hundred miles from home and their next door neighbour just happens to show up to chat, well, how did they know? Did they have a tracking device? Had they been told? Was it all a coincidence (which then needs to be written up as something surprising, not ignored)?
With all these points, the same principle applies. Even though characters are acting in the ways you decide to further the needs of the story, they should not appear to be doing so. They should appear to be acting in natural, or at least explicable ways. Ways that make sense to them, and to your audience. And remember, if you’re stuck for a way to get them out of a scene, you can always do what Shakespeare did, and reach for an enraged bear.