Out in the cold or one of the gang: Initial contacts set the scene
https://phys.org/news/2018-05-cold-gang-contacts-scene.html
By running a series of experiments, the researchers were able to confirm that social exclusion was not so much an instrument to discipline others, but rather an unintended side effect. This side effect arises when people choose to join up with individuals they have previously had good experiences with as a result of simple learning mechanisms. In other words, if the first random grouping in a social situation works out well, people have a tendency to repeat it. This means, however, that others are excluded from the interaction and thereby incidentally ostracized.
"The tendency to repeat what previously worked out well is a basic aspect of human psychology, which means that we stick to satisfactory groupings," says Björn Lindström. He gives two examples of the mechanism at work: "Cliques, e.g. of classmates, that exist at the beginning of the school year are usually still the same at the end of the year. Or, at work, it sometimes takes years for us to realize that the person a few offices further down the hall is actually a great guy. He simply wasn't part of one our first few interactions and then fell off our radar".