A lot of GMs actively hate the speak with dead spell for making it impossible to run a cool murder-mystery campaign in D&D. But in my experience, the reason many GMs feel that way is that they’ve let themselves be convinced by forceful players that the text of speak with dead says words to the effect of:
“You grant the semblance of life and intelligence to a corpse of your choice within range, allowing it to answer any question relating to its death with perfect accuracy, including the name, description, mailing address, and shoe size of their murderer.”
Except, of course, the spell doesn’t say that. And within the scope of what the spell doesn’t say, there’s lot of room to make sure speak with dead doesn’t mess with your ability to get your detective story on.
First, always remember that a person (dead or alive) can’t name what they can’t see. Magical disguise is a potent hedge against identification by the living or the dead. But so is a simple mask, a hood pulled down in an area of dim light, or a scarf quickly tied beneath the eyes. Creatures intent on evil deeds typically understand the importance of not being seen — and further understand that in a magical milieu, a victim is always a potential observer even after their demise.
Even when the victim is aware of who’s responsible for shuffling them off this mortal coil, remember that speak with dead allows a caster to question a corpse’s animating spirit — not to access the full consciousness of the person who died. Villains will thus understand how easy it is to confuse that spirit with false information. As a victim breathes their last, imagine a killer they don’t know leaning over them and saying clearly, “My name is John Smith! Remember that John Smith did this to you!” In the hands of a canny villain and a deft DM, speak with dead can be a perfect vehicle not just for deflecting suspicion from the real killer, but for framing someone else for a crime they didn’t commit.
Always remember that characters living in a fantasy world filled with magic are aware of that magic, even if they’ve never seen or experienced it themselves. So NPCs and villains being aware of speak with dead and what it does can keep the effect of the spell in mind if they find themselves involved in a lethal altercation. An easy analogy in our own world is taking fingerprints as crime-scene evidence — a practice for which most people have no idea how it actually works, but which we’re all generally aware of. Anyone who’s seen a police procedural has seen criminals and other ne’er-do-wells wiping fingerprints off surfaces before the investigators arrive. And in the same way, a villain in a fantasy campaign is going to understand the risks involved in a dead character telling the story of how they met their end, and will do what’s necessary to work around that.