Hearsay is a statement by someone to a witness who, while testifying in court, repeats the statement. The statement is hearsay only if it is offered for the truth of its contents. In general, courts exclude hearsay evidence in trials, criminal or otherwise. The hearsay ban aims to prevent juries from considering secondhand information that hasn't been subject to cross examination.
The goal of the hearsay rule is to make sure the evidence at trial is as reliable as possible. Criminal defendants face dire consequences, and courts don't want them convicted on the gossip flying around town. The legal system wants witnesses who have something to say to be in court so that lawyers can cross-examine them and juries can assess their honesty, possible mistakes, and potential bias.
For example, if Bob is on trial for murder, Henry can't testify that he heard Claire say that before the events in question Bob had a gun and was acting like a maniac. The court needs Claire's testimony regarding her exact observations, not Henry's secondhand story about what she allegedly reported observing. Without Claire, the jury can't get the details of her observations or determine what exactly she meant when she said it. Is she a compulsive liar? Was she joking? Does she hate Bob? Did Henry correctly recite what she said? No one can ask her any of these questions if she's not in court.
Not every out-of-court statement is forbidden. If the statement is used to prove something besides the content of the statement, it's not hearsay. For example, if Henry heard Claire call Bob a jerk, Bob's lawyer can ask Henry to recount the insult in court, not to prove that Bob is a jerk, but to show Claire's state of mind—that she was angry or that she doesn't like Bob (assuming these issues are relevant to the trial).
Likewise, Henry could also testify to hearing Claire telling Bob to "watch out" because there's no fact within the statement to prove or disprove. Rather, the threat is potentially relevant because it might show state of mind, such as Bob being afraid of Claire, Claire disliking Bob, and so on.
The hearsay rule has many exceptions. These exceptions (too numerous and nuanced to list here) allow for the admission of hearsay when the circumstances make that hearsay sufficiently reliable. A couple of the acknowledged exceptions are:
In criminal cases, the Confrontation Clause of the Sixth Amendment often operates in conjunction with the hearsay rule to prevent admission of out-of-court statements. The Confrontation Clause protects the right of criminal defendants to cross-examine witnesses against them. In many cases, both the hearsay rule and the Confrontation Clause can exclude evidence. For example, a court could bar Claire's statement to a police officer that Bob had a gun and was acting like a maniac with either the hearsay rule or the Confrontation Clause. Even if an exception to the hearsay rule applied, the Confrontation Clause would likely prohibit the officer from testifying to Claire's statement because Bob didn't have a chance to cross-examine her about it.