"And an innocent and righteous person you shall not slay"—Exodus 23:7.
We are forbidden to punish an individual based on circumstantial evidence, even if the person's guilt is virtually certain.
For example: A person was pursuing his enemy with the intent to murder him. The pursued escaped into a house, followed by the pursuer. Witnesses then enter the house and find the victim lying murdered, still convulsing, and the pursuer standing over him holding a knife—both people covered with blood. The courts may not execute the pursuer since there were no witnesses who actually saw the murder.
Though this law might seem unjust [as it will inevitably lead to the exoneration of certain criminals], here's the rationale:
In the realm of the possible, some possibilities are extremely probable, some are extremely unlikely, and then there's the full broad gamut of possibilities that fall somewhere between these two extremes. If the Torah were to allow the courts to punish an individual in an instance where the probability of guilt is almost definite (similar to the above example), then the courts would also come to punish in cases in which the guilt is less and less probable, until they would execute defendants based on flimsy estimation according to the judge's imagination.
Therefore G‑d "closed the door" to this possibility and forbade any punishment unless there are witnesses who are certain beyond a doubt that the event transpired and that there is no other possible explanation.
If we do not inflict punishment, even when the offense is most probable, the worst that could happen is that someone who is really guilty would be found innocent. But if a punishment were implemented based on circumstantial evidence, it is possible that someday an innocent person would be executed. And it is preferable that a thousand guilty people be set free than to execute one innocent person.
Similarly, if two witnesses testified that a person committed two different capital offenses, each one having seen only one of the acts – e.g., one witness testified that he saw a person working on Shabbat, and another witness testified that he saw the person worshipping idols – that person cannot be executed.