Although this punishment is not mentioned in the Qu'ran, it is the subject of a number of strong ahadith - Rasulallah (may the peace and blessings of Allah subhanahu wa ta'alaa be upon him) is reported to have dealt with a number of adulterers of both genders this way and it is therefore considered a part of the Shariah. As a revert, I used to think that it was barbaric, until an Alimah explained it to me in its full context and I began to understand that it is actually a great mercy from Allah subhana wa ta'alaa that helps to preserve a peaceful and safe society. Although it is undoubtedly a harsh punishment, if you stop and think for a moment about the incredible amount of damage that an adulterous relationship can cause - to the immediately affected families and to society in general - then you can understand why Allah subhanahu wa ta'alaa has ordained that this severe punishment be administered. As with other Hudud punishments, it is meted out in public so that everyone can witness the suffering of the guilty party, see that justice has been done and take on board the warning not to disobey Allah subhanahu wa ta'alaa in the same way. In reality of course the standards of proof required before the sentence could be passed are incredibly high and it is an very effective deterrent in any case, so it has only been used correctly a handful of times in 1400+ years. Not a nice thing to happen to anyone, but easily avoided by staying within the bounds of Islam, insha'allah.