A horn relay works by modifying the connection between the horn and the input, preventing damage in the system. Non-standard horns in vehicles may require relays to support them because they need differing levels of charge in order to function properly. This is essentially a middle-man part that picks up the slack in the system and allows for modified horn systems without completely replacing every component.
When a horn system is activated, the horn switch is pressed, completing a circuit of current from the battery to the horn. For custom horns that require a stronger charge to work, installing them without modification to the system can cause this switch to burn out thanks to passing more electricity through it than it was designed to handle. The horn relay is given this job instead, with the original switch acting as a signaller for the relay to send the electrical charge to the horns.
Relays tend to burn out more easily than switches do, but they are cheaper than switches to replace or install. This makes them a decent alternative to a full replacement of a vehicle's horn system, as otherwise a new switch would need to be found, and switches are fairly expensive in comparison.