The precise mechanism is not fully known as far as I'm aware, However, the general hypothesis is that copper metal reacts with the slime that covers snails and slugs, resulting in an unpleasant electro-neural signal (similar to an electrical shock) that repels them.
This hypothesis makes sense, because snail slime is mostly water with dissolved proteins, glycoproteins, and metal ions.
Snails have a relatively simple nervous system, composed mostly of ganglions that receive inputs from the outside world via external sensory neurons.
Since neural action potentials are often regulated by fluctuation in metal ion concentrations across neuronal membranes, it makes sense that copper ions may induce action potentials in sensory neurons on the snail/slug's foot, causing some kind of painful/aversive stimuli.
Again, I could not find published research that fully tests this hypothesis, and an expert on mollusk biology would likely know a lot more, but the data regarding the repulsive effects of copper towards snails and slugs seems very consistent, even though the mechanism may not be fully understood.