It's reparation, it's an indulgence (at least under the old Raccolta), and besides it makes the swearer think about what is usually just completely thoughtless swearing with no real ill intent.
Our little nuns used to tell us to pray for the person using God's name in vain. I still do. It's automatic now, but I find I'm doing it a LOT more often now than I ever did then.