First of all I want to say that swarming is NOT a bad thing! It means that your hive is healthy and growing! Now that I've made that clear, I'll tell you why bees swarm.
The first reason is because it's in their nature. Think about bees living in the wild. How do they replenish the earth with more bees? They create a split from their hive and make a new hive with that split. That is a swarm. So, when you hear beekeepers say they are making splits, what they are doing is trying to prevent their hive from swarming and in doing so getting an additional hive to add to their addiction, I mean hobby! ;)
When your hive makes it through winter and Spring is gearing up, the bees nature is to replenish the earth. So, they split because it's Spring.
The other reason they swarm is when they run out of room. If you get home with a NUC of bees and you leave it in the NUC box, the bees will swarm. Probably even a few times throughout the summer.
Bees need room to grow. Remember a queen can lay anywhere from 1,000-2,000 eggs a day during the peak bee season. That's a lot of bees being born.
Keep in mind that swarming is not the same thing as absconding. When a hive absconds it means every single bee just up and leaves the hive. That is due to an issue in the hive, most typically mites. But, it can also be a hive beetle infestation or a critter messing with it.
Now that I've shared the reasons they swarm, I'll tell you what happens inside the hive before and after it swarms.
The bees have a meeting and decide they are going to swarm. I'm joking, but you get my point. A laying queen is too heavy to fly long distances, so the workers will stop feeding her so she will stop laying eggs. The workers make 10-20 replacement queens (swarm cells), from the eggs she lays before she is put on her swarm diet. Once those swarm cells are capped, the old queen and 1/2 the hive take off to a new home. They know exactly where they are going before they leave, because scout bees have been looking for a new place to create a new hive. So, why do they hang on trees? They're resting on their journey to their new home.
What's left behind after the swarm is 10-20 virgin queens who are going to basically either fight to the death, or the first one born will go and sting all of the others to death inside their cells. Sometimes a virgin will swarm with the original queen and there's a fight once they find a new home. Sometimes there are a couple of swarms, one with the original queen, and another one with a virgin. Those are cast off swarms.
The virgin queen that is victorious and basically a bad ass, goes on her mating flight and hooks up with several drones. (don't judge). She flies home and is now the queen of the other 1/2 of the bees that were left behind. The next Spring this process will be repeated more than likely. In closing, I'm not saying that every single hive that overwinters will swarm. I'm saying it is highly likely they will. Set your swarm traps folks! Remember, a swarm in May is worth a load of hay...a swarm in June is worth a silver spoon...but a swarm in July is not worth a fly!