It's part of the Flight of Fight response-blood moves from your extermities to your core, your vision and awareness improve, digestion stops, and you sweat.
IIRC, because all the extra work raises your core temp, and sweating helps you to cool off. There are some other theories, too, though, such as the perfuse amount of sweating is a hold over from when humans/apes used to more readily transmit messages through scent. Sweating more would acompany the extretion of stress-related hormone, which other individuals could pick up on.
I forget most of the specifics, though.