Going to trial happens when litigants cannot agree on the contested issues. Trial is a final hearing so that a Court can make those decisions. A settlement avoids Court, but may include terms that are unfair or unacceptable. Trial puts these decisions into the hands of a Judge or Jury.
Less than 10% of cases end up needing Final Trial to resolve them, because 90% of cases will settle before then. Trials are usually held in the cases with the most at stake - child custody and/or large amounts of money. Normally, rational people with good attorneys should be able to settle a case on their own. But, that is not always the case, and very frequently one party is not rational. Or one (or both) attorneys are not very good, or won't tell their clients what they don't want to hear. Or sometimes, there are issues that just cannot be settled, such as when one parent wants to move far away with the kids and the other outright objects.
Trials can be in front of a Judge or Jury. Jury trials are more expensive, and that can be a factor in choosing one. If one side is more able or willing to spend money on lawyers, they can ask for a Jury Trial in an attempt to wear out their opponent financially. This tactic can be quite successful whether that is fair or not.There is an enormous amount of theorizing about which is better. The answer is: it depends. Be sure to consult with an experienced attorney about this issue, because it really can be important.