Fish swim in schools because they were told to do so by their mothers for their own safety.
It's very similar to human teenagers walking in an amusement park together, when a Mother says, "Stay with the group when you go to the amusement park." There is safety in numbers. A predator is more likely to seek a fish that is swimming alone, or a fish that is dying or already dead. And that is true for all animals in the animal kingdom. A baby antelope will be struck down by a lion because he is smaller and weaker , and can't run as fast as the other antelopes.
It's their natural instinct to swim in schools. Fish do so, to stay alive, and because they aren't evolved enough to carry a stun gun so that bigger fish won't eat them.
Fish are only doing what nature has taught them to do, they swim in schools to be protected from other larger fish. It's amazing to see brightly colored fish swim past in their array of tails and fins moving as if they were one creature. And if a large fish such as a shark darts past them, they all move away at the same time as if they have been practicing this ballet of swimming for millions of years.
That's because fish that swim in schools such as minnows, tetras, and tangs have been swimming in schools for possibly millions of years. After all it takes a lot of practice to get those fast darting, and squishing to and fro movements down to a science. They need to keep the species alive, therefore they are swimming as one cohesive unit to try to keep all the fish alive.
Which raises the question of who is the leader in the group? One fish becomes the leader due to the fact that he or she is the dominant fish. The leader in the school will fight off another leader until the death sometimes to take the lead. The leader will then lead the school to what he thinks is the safest route. And all those followers will them fall in line behind the leader who is trying to do his level headed best to keep everybody safe.
Fish that swim in schools for the most part are the smallest creatures in the sea, and they need the protection against larger predators. When a hungry large predator approaches a school of fish, the first line of defense begins with many confusing silvery flashes and beautiful displays of stripes that confuse the larger fish into thinking the school is one large fish. Therefore, the larger fish will swim away, knowing he has no chance in eating a fish as large as he is or larger than he is.
Fish also swim in schools to make it easier to find food by acting as a unit. There are more pairs of eyes looking and they are helping each other by working as a group. When an intruder swims past their under sea home, a school of fish darting out at the intruder looks much more imposing than one small nasty fish with a bad attitude.
Even large fish such as whales swim in groups to migrate from Hawaii to Alaska every year to keep every member of the group safe. By swimming in a group of whales, the calves are easier to protect. When a shark comes along looking for an easy target and possible meal, then the large group of whales can keep the babies protected. Usually a calf will swim with it's mother, but at the same time, the group can help keep the calves out of harm's way. A herd of elephants will surround the younger elephants to keep them safe from the clutches of lions and tigers.
Swimming in a school is the way fish stay safe, find food and fight off predators, much as human groups do, and as animal groups do also. While being in a group the members feel safer and they keep the younger adventurous kids safe from harm. This way the species perpetuates itself and lives on to see a new day.