I've read the wiki on it and know that trial by combat did exist in many places in Europe. I don't understand, however, the theory behind it. In what way could a fight determine who was right or wrong in a legal battle? In societies that allowed it, could the best dueler of the town just do whatever he wanted because he would never lose a trial by combat?
Robert Barlett sums it up well enough when he writes:
As an ordeal in the most fundemental sense of the word, [trial by battle] was supposed to reveal the judgement of God.
That is to say, it determined who was right and wrong in a legal dispute because God would ensure that the outcome was correct. But of course, it isn't quite that simple. Trial by battle (nor ordeals in general) wasn't meant to be used in all circumstances. Rather, while there were many different crimes for which, in the period of its use, we see its application for crimes where physical evidence was scarce, disputed or not present at all - ie the case based entirely by accusation. One of the most famous Trials by Combat was the 1163 accusation by Robert de Montfort that Henry of Essex had committed treason by abandoning the King's standard and falsly claiming the king was dead. With nothing conclusive to either side of the argument, Robert "proved" his claim by defeating Henry.
In England, the use of 'Battle' was especially common in civil trials with the accused able to choose either Battle or Jury. In this particular situation, hired champions were allowed, even if the law was fuzzy on their allowability, which meant that it was less so the best dueler around who got to be a bully, as you posit, but rather the wealthiest person! A rich landowner would even have a Champion on retainer to defend them in court if necessary.
Now of course, this in of itself kind of points to the absurdity of the system, and an awareness that God might choose the outcome, but you could still try to stack the deck in your favor with the more accomplished fighter, and sketicism of the Ordel was as old as the act itself. King Liudprand of the Lombard noted, for instance, in the 8th century.
We are unsure about the judgement of God and have heard of many men who have lost their case unjustly through trial by combat.
It wasn't, however, until the 13th century that the relgious sanction starts to decline, but the judicial duel would limp along in the secular world for some time to go still, dying off in the 15th and 16th centuries. I've written a bit more about that here.
Mostly drawing on Robert Barlett's "Trial by Fire and Water: The Medieval Judicial Ordeal". While it is from the late 19th century, George Neilson's "Trial by Combat" is freely available and might also provide you with further reading material.