The primary reason is to reduce the weight of an aircraft. Aircraft are designed to land at a maximum weight lower than their maximum weight. In order to be under that maximum landing weight, they must either burn that fuel during flight or dump it.
There is no requirement for them to dump fuel. This decision is up to the pilot. They may choose to land the aircraft "overweight", meaning over the maximum landing weight. In this case the aircraft will have to undergo an inspection to ensure that nothing was damaged. On some aircraft, an inspection is only required if the touchdown acceleration was over a certain amount (like 1.7G).
Dumping fuel will generally be an issue with a plane that has taken off for a long flight and has to divert for some issue. The pilot must decide how urgent the emergency is. If it is an urgent problem, such as engine failure, medical emergency, hydraulic issues, or fire, their priority is to land ASAP regardless of weight. They may dump fuel while headed to a diversion airport if they can.
If the emergency is not as urgent, the pilot may decide that they do not want to continue the flight, especially if it involves long stretches over water without diversion airports. In this case they can hold somewhere near a diversion airport to burn off or dump fuel until they are comfortable with their landing weight.
For example, the 777-200ER can take off at 656,000 lb, but maximum landing weight is 470,000 lb. This means they could have to dump 150,000 lb of fuel if they encounter an issue at the beginning of a long flight.
The amount they leave after dumping will be up to the pilot. For serious gear issues, they may want to be as light as possible and only leave a minimum amount of fuel in the tanks (on a 737, this is about 4,000 lb). For other instances, they may be satisfied with the maximum landing weight and not want to spend any more time dumping or burning fuel. No pilot wants to dump a bunch of fuel and then end up needing it later.