Team building is a common name for different type of activities. It is used for improving social relations and defining roles within a team that often includes external business. It is different than team training which is designed to improve efficiency and not social relations.
Team building in sports develop behavior and skills that increase team functioning. One of the basic strategies is to stress team identity. It can increase the sensation of common-shared future.
Fun is important component of team building but its intention is to become more productive, focused and effective. Recreational activities can be helpful but you have to bear in mind the team member abilities.