When did dueling become illegal? When and why did it go out of style? What were the motivations behind making it illegal?

by Tristan_Jay
Georgy_K_Zhukov

Your first question supposes that dueling was legal when it was still a "thing", which for the most part is not the case. Even participating in a duel could be a capital offense in some cases (Henry IV of France made issuing a challenge one!), and killing a man was very much so, but the simple fact is that you could generally expect a pardon, a prosecutor not pursuing the case, or else that a jury would either refuse to convict or give a small slap on the wrist (A few months confinement in cushy lodgings). In the 19th century UK for instance, there were barely any convictions at all. In 1814 the "The Edinburgh Review" noted how entirely toothless the law was with regards to the duel:

This law is a mere dead letter; for what with the unwillingness of prosecutors, the connivance first of police-officers, then of judges - the feelings of juries, and the corresponding feeling in the place of last resort, no instance is known of the law being executed against any person for being engaged in a duel, fought in what is called a fair manner.

Fair manner is the key here, but even excluding that, the Review is only off by one. The lone British duelist to be executed during the 19th Century was Maj. Campbell, for killing Capt. Boyd in 1807, and it was the circumstances of the duel that lead to his hanging, not the duel itself. The duel had been conducted in great haste, with no witnesses, and entirely contrary to accepted practice. Upon hearing the exchange of shots in the room the two had gone off to, others came into the room to hear the dying Boyd insist that "Campbell you hurried me, you are a bad man!" and "O my Campbell, you know I wanted you to wait and to have friends." Additionally, Campbell then fled and lived under a false name for a few months which did him no favors either. He turned himself in eventually, but was convicted and denied a reduced sentence. As one chronicler noted, "His offence was not that he killed Boyd, but that he killed him contrary to established rules." (All the above, source: A Polite Exchange of Bullets by Stephen Banks)

So regarding the first question, what this is all to say is that generally speaking, dueling was illegal, and almost all countries had explicit laws against it (One notable exception being post-Revolutionary France, where a duel wasn't illegal, but killing a man would fall under homicide laws).

As for your second question, I'd point you here where I previously did a quick rundown of the points when dueling declined in various places.