Is it true that a person's sins would disappear if he is given the punishment that is decided in sharia'h?
What is the punishment of touching a non-mahram? And by touching, I mean handshake and in an extreme case, a hug. Not any other form of physical intimacy that could have caused arousal. Not intercourse. Just a handshake or a hug. Though it is clear that the punishment of having intercourse is 70 whips.
First of all you should do sincere repentance from what you did. Even if to me handshaking isn't a (big) sin because in some cases it would be considered as impolite! And IMO the handshaking matter was a special order for our Messenger (peace be upon him). And Islam or at least some madhabs respect some local customs: as an example the people of Medina used to do female circumcision in jahliya and Islam didn't prohibit it. On the other Hand the man in Mekka used to tap their disobeying wife's while in Medina this was not the case and the Quran allowed it but with careful/cautious/light tapping!
Back to the handshakes and hugging this is still (very much) far away from zina (even if it is something that may lead to it, and therefore something one should or is strongly asked to avoid) so there's no (by shari'a prescribed) punishment for that! But as for any sin repentance would be needed!
On the other hand scholars say that a sincere repentance would make sins disappear even for sins which should be (but are not) punished according to shari'a (see the links below in Arabic)! This would mean you should do repentance and expiation and real regretting and turn the sins into good deeds like praying, fasting,..., doing good things, helping: Being a good Muslim and not redoing what those sins!
Because of the following Verses:
Do they not know that it is Allah who accepts repentance from His servants and receives charities and that it is Allah who is the Accepting of repentance, the Merciful? Surat at-Tawba(9:104)
Except for those who repent, believe and do righteous work. For them Allah will replace their evil deeds with good. And ever is Allah Forgiving and Merciful. Surat al-Furqan(25:70)
And it is He who accepts repentance from his servants and pardons misdeeds, and He knows what you do. Surat ash-Shura(42:25)
Verses 1 and 3 just tell as that Allah accept repentance (if it is sincere as explained above) while Verse 2 tells us that Allah even turn sins into good deeds if one is faithful and and repent sincerely!
And Allah knows best!