One reason that people label and group others is because all people tend to label and group everything. It is probably innate in humanity, and it is one important way children learn.
They do not discover that a fire burns, they learn that fire burns. They do not fear that a dog will bite, but that all dogs bite. For children in certain stages of development, labeling and grouping and stereotyping is an efficient shortcut to understanding a world that is huge and confusing, and sometimes nearly impossible to comprehend.
Labels and groups are often inaccurate, but not always. Fire does burn, and dogs do bite. The generalizations and categorizations of stereotyping help children to master useful concepts quickly. Of course, stereotyping may possibly lead to phobias, and also to racial, ethnic and gender prejudice. The generalizations of an ignorant child will be less useful to an adult.
In any case, stereotyping is not the only cause of labeling and grouping of other people. Two other factors are emulation and peer pressure.
Children want to be like their parents. They copy their dress, their tastes and their way of looking at the world. Emulation is a display of loyalty and love, but it is also a way of establishing the first building blocks of an identity: I am like this because this is how my people are.
With age, children copy the other children and adults they admire. They may want shoes like Melody's and they may try to model their handwriting on the way their teacher, Ms. Washington, does it, even though they use their left hand and she uses her right. Later, still growing, they may dress like a famous singer does, or try to talk like a favorite professor.
Parents have to be careful about the behaviors they model for their children, and so do teachers and other role models. Children can absorb mistaken ideas about the world without anyone involved even noticing it's happening.
Everyone belongs to groups. They are a family member, a citizen of a country, members of an occupational group, and so on. The problem is that all groups enforce conformity to their norms, at least to a degree. Some groups enforce conformity quite rigidly.
To join some groups, a potential member must accept their world view, with all its prejudices. He or she must put on the uniform, in effect, and join the group in attaching certain labels to people outside the group. This is one of the costs of belonging.
However, belonging confers a sense of identity, a sense of safety, and a clear explanation of the way the world works. The explanation may be oversimplified and inaccurate, but it confers a sense of certainty, and frees a member from the discomfort of doubt and questioning.
Adults think in stereotypes to a degree, perhaps, and will never be able to entirely free themselves from them. However, people can free themselves, consciously, from the idea that because one dog bites they all do. Grown human beings no longer need to share all the views of their parents, their teachers or their mentors. The work of maturity is to stop being merely a member of a group and to become an individual who declines to put labels on individual experiences.