Before 1800, european governments recognized that privateering or piracy was a legitimate method of warfare, provided that rules were followed. The pirates had to have licenses or letters of marque from their governments, could only attack ships from nations with which they were at war, had to treat prisoners humanely, and had to keep records proving that they had followed the rules. If the rules were followed, the pirates could take captured ships and cargo to neutral ports, and sell the ships and cargo. The new owners' ownership of the captured ships and cargo would not disputed by anyone, not even the original owners. The neutrality of the neutral port would not be questioned.
In the War of 1812 between Britain and America, piracy was one of the main tactics of America. Britain had a larger merchant fleet. The best route from south america and the caribbean to Britain is to follow the gulf stream, which is near the coast of America. So it was easy for America to engage in piracy, because there were many British ships near America.
The leaders of Britain realized that since Britain was the leading trading nation, Britain was more vulnerable to piracy than any other nation. So Britain attempted to persuade other nations to sign treaties changing the rules of war and prohibiting piracy in wartime. According to the new rules, neutral ports were required to punish pirates as war criminals. If pirates sold the captured ships and cargo, the new owners had to be punished for buying stolen property.
The new rules did not allow random attacks on merchant ships, but did allow blockades, where one nation uses its official navy, not licensed pirates, to attack all merchant ships of the enemy. The new rules effectively said that you could not attack one enemy ship; you had to attack all enemy ships or no enemy ships. The british merchant fleet was so large and the navies of other nations were so small that this prohibited any other nation from attacking british merchant ships. But the british navy was large enough to attack the small merchant fleets of any other nation.
The leaders of Britain realized that by changing the rules of war, they could make it easier for Britain to win wars.
Before 1900, european governments recognized that warships could attack merchant ships in wartime, provided that rules were followed. There had to be an official blockade. The warship had to identify itself and had to search the enemy ship for proof that it really was an enemy ship, but could sink the enemy ship without a search if the enemy ship resisted being searched.
In World War I, Germany built many submarines and used the submarines to attack british merchant ships. In accordance with the rules of war, Germany declared an official blockade, and the submarine crews attempted to search british merchant ships. But First Lord of the Admiralty Winston Churchill, who would later be prime minister in World War II, ordered british merchant ships to resist being searched, and to either ram the submarine or run away. The german submarines were slower and more susceptible to leaks than the british merchant ships, so these british tactics rendered the german blockade ineffective. In response, Germany ordered submarines to not identify themselves and to make no attempt to search enemy ships, and to sink enemy ships on sight.