Horde Mentality, known internally as a 'FollowOthersGoal' is the system that causes Spore Mobs to group together into large swarms, pairing up and following nearby allies.
Infected, Evolved, Bairns, Scampers, and Gastgebers can have an assigned 'partner'. They'll check every second if they have one. If they don't, they check for any nearby valid partners within ~32 block radius. The closest one will be assigned as their partner. Mobs will only chose to partner with specific Mob tiers. The following are the parameters:
Infected and Bairns will partner with other Infected, Evolved, Hyper Evolved, and Bairns.
Evolved, Scampers, and Gastgebers will partner with other Evolved, Hyper Evolved, Scampers, Gastgebers, and Calamities.
Hyper Evolved and Calamities will not partner with other Mobs, however other Mobs are able to partner with them.
Partners are never cleared, meaning once a Mob has a partner, they don't change it or get another.
While a Mob has a partner, they will attempt to pathfind to their partner every tick.
Trivia
Due to the hordes system being a very old feature, it's extremely outdated. It barely functions as it is and causes major performance issues. Furthermore, following partners aren't NBT data and aren't synced between clients, meaning if given the right situation, it could be possible for a client desync to occur.