Here’s the scenario - you’re a suspect in a murder. There’s motive, opportunity, physical evidence, all that. One problem for the prosecutor - you have a good alibi - specifically, a credible, trustworthy witness who will swear up and down that you were with him the whole time between the last time the victim was seen alive and the discovery of the body. If it weren’t for that sole witness, the prosecutor would have a good case against you.
Say the witness dies under sudden but completely innocent circumstances a few months later - like a stroke where he never regains consciousness. What would prevent an unscrupulous prosecutor from charging you with the murder now that you no longer have a witness to testify that you were with him the whole time?
The death of the witness doesn’t mean your alibi is lost. The witness might have reported his observations to the police in an official questioning, of which records exist. He might have informally told other people about his observations, and these other people might be available to testify that they heard the deceased say that you cannot possibly have committed the crime. This is all evidence which can be used in a trial.
Of course, this sort of evidence is less direct than a testimony of the witness himself, and the judge or the jury will certainly take this into consideration when assessing the credibility of this evidence. But it’s not as if the alibi were lost altogether.
The alibi witness will probably have testified at the grand jury or pre-trial evidence hearing. If he dies, the record of that testimony can be entered as evidence.
He probable also told his story to the cops during the investigation, and the police can provide records (if any) or their own recollections as to what he said.
What they said, although it’s always better (assuming the witness will make a good impression on the stand, which the OP seems to imply) to have a live witness. Sometimes that’s just not possible, though.