What is the evolutionary rationale for palm sweating?

Sweaty palms seems to be a reaction to stress, anxiety, etc. For our forest-inhabiting primate ancestors sweaty palms could cause unwanted side-effects such as slipping off tree branches under stressful conditions, like when being chased by a predator.

Why did palm sweating became a reaction to fear, worry, anxiety etc in the course of human evolution? What is the benefit of sweaty palms?

As @Ben states, every theory of 'why' we evolve a trait is just a guess and never more than part of the story. But there are theories.

The palms of our hands are a major source of heat transfer out of our body. For bears it is the nose and pads of their feet, for dogs it is their toungue, for us a major portal for heat out of our body is the palms of the hands.

Black bears are extremely well-insulated animals, equipped with a heavy coat of fur and a thick layer of subcutaneous fat that help them maintain their body temperature as they hibernate through winter. But once spring arrives and temperatures rise, these same bears face a greater risk of overheating than of hypothermia. How do they dump heat without changing insulation layers?

Heller and Grahn discovered that bears and, in fact, nearly all mammals have built-in radiators: hairless areas of the body that feature extensive networks of veins very close to the surface of the skin.

Rabbits have them in their ears, rats have them in their tails, dogs have them in their tongues. Heat transfer with the environment overwhelmingly occurs on these relatively small patches of skin. When you look at a thermal scan of a bear, the animal is mostly indistinguishable from the background. But the pads of the bear's feet and the tip of the nose look like they're on fire.

These networks of veins, known as AVAs (arteriovenous anastomoses) seem exclusively devoted to rapid temperature management. They don't supply nutrition to the skin, and they have highly variable blood flow, ranging from negligible in cold weather to as much as 60 percent of total cardiac output during hot weather or exercise.

Given this, one could see how the palms of our hands are more likely to react to emotional situations where the heart rate elevates and sometimes we get hot under the collar. The AVAs will

I am not physiologist, but the quote above comes from an article I stumbled upon a few months ago. They use the AVAs to reduce the swelling associated with exercise and got some amazing results. I guess that's another story though.

There isn't necessarily a nice neat evolutionary rationale or advantage behind all of the observable traits found in all organisms.

It's perhaps more likely that there simply was not enough selection pressure against having sweaty palms to eradicate it from the gene pool entirely.

It is almost certainly to improve grip. There is a different type of sweat gland (eccrine sweat glands) in the palms and soles. The sympathetic nervous system (one feature of which is epinephrine / adrenaline) feeds those glands, so if something is scary or tense they kick in.

Our ancestors were in trees. Our close relatives still are. Scary situations often means moving fast through the trees. Or it is scary because you are about to fall! Either way you need your good grip: hands and feet both back in those days, or for our great ape cousins.

A little bit of moisture makes hands much more grippy. Especially if your hands are not very clean. People sometimes spit on their hands to improve grip.

Because feet and hands touch so many things, I would think that sweat would help act as a protector from various pathogens as well as scent marking, heat transfer, or stress symptoms. Both the salt and fluid in sweat might wash some pathogens away.

It was advantageous for our ancestor's grip while tree climbing millions of years ago, so the best current theory claims.