Electric fences are set up so that the horses do not run away breaking through the fence or try to jump over them. Due to the shocks they try to keep away from the fence.
There is electric power supply connected to metallic fences. The fence is at a higher potential as compared to the ground. The animal bodies are conductors of electricity. The reason is we have salts, minerals, acids, bases and water in our body.
When a horse touches the fence, an electric circuit is formed from the fence to the horse , its legs to the ground. The ground is at a potential of 0. Thus due to the potential difference difference, electricity passes through the body of the horses.
Due to the current, the body gets heated up, the passing of electrons creates a sensation though the body. This results in a shock.
the voltage is kept low enough not to damage or hurt the horses.