The feeling of being left out, cut off from your community to confront the world alone is terrifying, which is why the threat of ostracism has always been used to make people compliant. Whether on a relatively large scale like excommunication or a relatively small scale like being disowned within a nuclear family the psychology is the same.
But why does feeling left out hurt so much? Who cares if you’re excluded from membership in this or that group? At the fundamental level it hurts because being part of something bigger than you expands the borders of your small Self, making you resilient in the face of existential anxiety.
Exclusion makes you painfully aware of your smallness, your separateness, the fact that you are alone, and with this awareness existential anxiety comes rushing in. Really the unconscious reason that exclusive groups of all kinds exist, where gaining membership is difficult, is that those who gain entrance feel an inflated sense of strength and importance, of superiority, and these feelings protect them from thinking too much about their own precarious positions as mortal, separate biological organisms doomed to one day perish alone.