Nothing happens to the spell.
Touch spells don't require concentration to hold the charge, as I've touched on before. This means that the only ways to lose the touch spell (barring things like anti-magic fields and dispel magic spells) are to discharge it on a target, let its duration expire (if it's one of the rare touch spells with a non-instant duration like produce flame), cast another spell, or die.
While the hand-rule described in the linked answer isn't rules-as-written, I would strongly advise against having a touch spell discharge on anything that hits the person holding it. Not only does it lead to shenanigans, like having a downed caster accidentally kill their healer when they touch them to make a Heal check or deliver a cure light wounds spell, but players can pick up that line of logic and run with it forever.
Assuming the accidental touch clause means "the very first touch no matter what":
If a touch spell can affect an object, then it always hits something you're holding or wearing unless you are completely naked and flying/levitating when you cast it. You don't have time to reach out and touch something else because you're already in contact with several objects.
If it can only affect creatures, then it almost always hits you. The number of times you come into contact with yourself in a given round is immeasurable. Even ignoring various internal parts touching each other off and on as they do their jobs of keeping you alive, your fingers touch one another almost every time you flex or relax any one of them. Your tongue touches your teeth, the inside of your mouth; your teeth touch each other from time to time. When you blink, your eyelids touch. When you smell something sour, your nose may touch your lip. If the wind blows, your hairs may touch your skin - or each other.
If your table uses critical failure rules, feel free to assume a natural 1 on the save against a stun or paralyze means the caster accidentally nails himself with his touch spell as he goes down. Not much different than a gish botching an Athletics roll and landing on his own sword. Just beware that players will die a lot if they have a 5% to get hit again - possibly by devastating magic - for getting hit with Stunning Fist or hold person. Just remember to apply it to the others, too - swords and arrows can be dangerous too when you fall in a heap.
If you actually use this fumble rule, please, PLEASE don't use it for when someone falls unconcious due to HP damage. Having someone self-execute by stabbing/shocking grasping themselves when they're already at negatives is a little more cruel than you should be aiming for in any game but Hackmaster.