1: Ignore all psychological and legal concerns, this is a biological question.
2: It’s NOT about necrophilia - obviously the recently deceased can’t get it up.
OK?
So, say a couple were considering children and he gets killed in a way that leaves his genitalia intact and apply rule #1
Could semen be extracted from his gonads and used to conceive a child with his widow?
(presumably via IVF)
I’ve read that sperm can survive outside the male for up to a week, given the right environment - ie a woman - presumably testicles would also be a pretty good environment too, so how long after death would they still be useful?
Assuming that semen was extracted promptly and frozen, probably indefinitely.
There are stallions that have been dead 20 years, but are still siring foals each spring, via artificial insemination. Presumably that could be done with humans, too.
I don’t have any direct experience with it, but I suspect there might be difficulties, if we’re not talking about a frozen donation made while the man was alive. Part of what this touches on is the difference between just sperm and semen - the seminal fluid produced in the prostate and other nearby organs is critical in feeding the sperm, protecting them, and it might play a role in conception, I’m not sure.
Once the man is dead, the prostate shuts down and I’d imagine semen cannot be extracted, only sperm from the testicles, which might not be good enough. I don’t know how long the sperm would survive there without blood flow either.
Didn’t this happen on an old episode of ER? An old guy died and his young widow showed up with a technician wanting to use some kind of electric probe to extract his seed.
If nothing else, you could probably get a donation of spermless semen from, say, a man who’s had a vasectomy, and introduce surgically-extracted sperm into that. If the fluids are actually needed at all.
Sperm need to either stay warm enough or be completely frozen if they’re going to be viable. You also have consider enzymatic reactions and bacterial decomposition. Sperm don’t survive well in acidic environments, which is exactly what you get as a byproduct of bacterial growth. (The same article cited by the OP mentions that sperm in the acidic vagina get less than six hours).
I’d venture a guess that sperm would have to be harvested and frozen within a few hours of death for them to be viable as a group. A fraction might be hanging onto “life” even a day or two later, I’d guess. Once frozen, you’d have decades.