Many parks and recreational areas have outdoor basketball courts. A majority of the time, these courts will have chain link fences around them. The fences are metal but are somewhat flexible, so they won't damage the ball or player upon contact. These fences serve several purposes, such as keeping the ball close to the court, protecting more private courts, and preventing other park-goers from getting hit by a ball.
When playing basketball, it is common for the ball to go out of bounds. At a recreational level, there are no fans or coaching staff to throw the ball back onto the court. A chain link fence acts as a boundary around the court that prevents the ball from going too far away from the players. This decreases the chance of the ball getting lost, and allows for the game to move along faster since players do not have to run off the court to retrieve the ball.
Many athletic clubs or private homes can also have a basketball court. They too will use chain link fences, but will have locked gates in order to prevent unwanted players from coming onto the court. Typically, only members of athletic clubs have access to the facilities. Having a fence around the court allows the owners to protect the court and its equipment from non-members or intruders.
Having a chain link fence around a basketball court can also protect those around the outside of the court. If the ball gets thrown out of bounds, it could hit a spectator or another park-goer. The fence prevents this and keeps other members of the community safe.