As observed in another answer, evidence that a deceased person said something is prima facie hearsay and can be admitted under the various hearsay exceptions. Many jurisdictions have statutory exceptions for witnesses who die after making a formal statement of some kind. The accused may have the opportunity to object to such evidence on the ground that he or she has been unfairly deprived of the opportunity to cross-examine the witness. However, there are also some common law exceptions.
The following exceptions are detailed in section 1 of chapter 17 of Cross on Evidence: 'The Rule against Hearsay: Principal Exceptions at Common Law: Statements of Deceased Persons.' This is an Australian textbook, but the principles apply in any jurisdiction where the common law has not been supplanted by statute or local case law. (Because the source is Australian, it is worth adding the caveat that the common law has been replaced in most Australian jurisdictions by the Uniform Evidence Acts.)
Dying declarations: evidence that a deceased person said something under a 'settled hopeless expectation of death' is admissible in a trial for that person's murder or manslaughter. This rule is based on the scientifically dubious proposition that 'when the party is at the point of death, and when every hope of this world is gone: when every motive to falsehood is silenced, and the mind is induced by the most powerful considerations to speak the truth; a situation so solemn, and so awful, is considered by law as creating an obligation equal to that which is imposed by a positive oath administered in a Court of Justice': R v Woodcock (1789) 168 ER 352, 353. This exception has its own Wikipedia article. It is reproduced in many evidence statutes, including the (US) Federal Rules of Evidence, and remains significant today. One famous example of the use of this exception in Australia occurred in the trial of Bandali Debs and Jason Roberts for the 1998 Silk–Miller police murders. A significant piece of evidence against Roberts was the dying declaration of the murdered police officer Miller that there had been two offenders: see R v Debs & Roberts  VSCA 66 .
Declarations in the course of duty: evidence that a deceased witness recorded or reported something that it was his or her duty to report is admissible, provided the record or report was roughly contemporaneous and the witness had no motive to misrepresent the facts. In R v McGuire (1985) 81 Cr App R 323, the appellant had been convicted of arson after a trial in which the judge had admitted evidence of a scientific officer's report on the fire. The officer died before the trial. The Court of Appeal confirmed that the trial judge had been correct to admit the report so far as it dealt with the facts, and correct to exclude it so far as it offered an expert opinion – though another expert could have given an opinion on the basis of the facts in the report.
Declarations against interest: evidence that a deceased witness said or wrote something which they knew to be against their own pecuniary or proprietary interest is admissible. This exception is of limited use in a criminal trial, since it doesn't extend to admissions against penal interest, but it is still applicable. For example, in R v Rogers  1 Cr App R 374, the exception was accepted to be applicable in principle in a criminal trial for possession of heroin, but the Court of Appeal found that the trial judge correctly excluded evidence that a deceased person had admitted that the heroin belonged to him and other people were 'after him for the money for the heroin.'
Declarations as to public or general rights: an oral or written declaration by a deceased person concerning the existence of such a right is admissible provided it was made before a dispute had arisen. This rather obscure exception is rarely used in criminal cases. It was commonly used in disputes over land before the establishment of land registration systems. However, I was able to find one criminal case concerning a prosecution for obstructing a highway in Middlesex by building houses and buildings on it. In R v Berger  1 QB 823, a divisional court of the Queen's Bench Division granted a new trial on the basis that the trial judge had been wrong to admit a 'map attached to an inclosure award made in 1814' as evidence that the land in question was part of the highway.
Cross on Evidence identifies three other exceptions which are generally relevant only to succession cases: declarations as to pedigree (ie. ancestry), post-testamentary declarations of testators concerning the contents of their wills, and extra-testamentary statements of testators as to disinheritance. I have ignored these exceptions, since succession cases fall into a special category where the intentions of a deceased person tend to be the central issue.
The rationale of the exceptions described above is that for one reason or another, the statement was made in circumstances that (supposedly) make it inherently reliable. They are not intended to discourage accused persons from murdering witnesses. Many commentators have observed that admitting hearsay evidence only when it falls into an arbitrary and closed set of categories of supposedly reliable hearsay utterances is confusing and illogical, hence the prevalence of evidence statutes in the modern era. For example, the authors of Morgan and Maguire, 'Looking Backward and Forward at Evidence' (1937) 50(6) Harvard Law Review 909, 921 said:
In short, a picture of the hearsay rule with its exceptions would resemble an
old-fashioned crazy quilt made of patches cut from a group of paintings by
cubists, futurists and surrealists.