The rules don’t say. The accidental discharge rule is a single, throw-away line that isn’t given any support or explanation whatsoever. How, when, and why it works is left completely undefined.
It also leads to numerous (one example, another) questions and potentially serious rules exploits or failures.
More broadly, held charges are also under-defined. They aren’t quite a spell effect (for example, you don’t use up a spell’s duration while holding a charge of it), but they also aren’t quite the same as just a spell you have prepared.
Spell effects remain in place after their caster dies, unless they required that caster’s concentration. Touch spells don’t, so that doesn’t apply.
On the other hand, a caster loses all prepared spells when he or she dies. Should that apply to held charges as well? Who knows!
Basically, it’s kind of a mess, and the accidental-discharge rule in particular is just a giant rules hole. I strongly recommend ignoring it entirely.
But if you must have an answer, then I’ll just echo my answer about getting hit while holding a charge:
In general, you have to actively try to touch someone to trigger it. It requires an attack action on your part, an attack roll, and so on. In a Grapple, you have to win a Grapple check to get an attack.
A free, retributive effect like you propose is quite rare in 3.x, and usually quite weak. To be able to do it with just any touch spell is potentially overpowered and opens up shenanigans that are probably inappropriate.