This a common misunderstanding of the international laws of war, and international law in general.
In our personal lives the government can compel us to follow the law with the threat of overwhelming force; if I break the law I will be arrested, and regardless of how much I fight back I will not be able to stop it. Laws in our everyday lives are like commands from a parent to a child; the government, as the parent, can and will compel the child's obedience.
International law is different. If a state breaks international law, there is no entity willing or capable of using overwhelming force to compel obedience. States have armies and some have nuclear weapons; the amount of force required to compel a state to behave a certain way is huge, and generating that force is extremely costly. When states break international law there are consequences, but at the end of the day violence is generally not on the table.
Effective international law is a balancing act. An international standard of warfare that placed extremely strict standards on when it was permissible to kill civilians would make fighting a war significantly harder. No state would obey such a law because winning the war is the absolute highest priority, making the law worthless. Instead, laws of war try to outlaw actions that don't affect the ability of a country to win a war. No chemical or biological weapons (high explosives are more effective), humane treatment of prisoners (discourages the enemy fighting to the death), and no killing civilians unless in the pursuit of a military objective (if it's not in pursuit of a military objective, then it's a waste of resources). The goal of the laws of war is to prevent unnecessary violence, not prevent violence altogether. It's a case of "perfect is the enemy of good."
In our personal lives the government can compel us to follow the law with the threat of overwhelming force; if I break the law I will be arrested, and regardless of how much I fight back I will not be able to stop it. Laws in our everyday lives are like commands from a parent to a child; the government, as the parent, can and will compel the child's obedience.
International law is different. If a state breaks international law, there is no entity willing or capable of using overwhelming force to compel obedience. States have armies and some have nuclear weapons; the amount of force required to compel a state to behave a certain way is huge, and generating that force is extremely costly. When states break international law there are consequences, but at the end of the day violence is generally not on the table.
Effective international law is a balancing act. An international standard of warfare that placed extremely strict standards on when it was permissible to kill civilians would make fighting a war significantly harder. No state would obey such a law because winning the war is the absolute highest priority, making the law worthless. Instead, laws of war try to outlaw actions that don't affect the ability of a country to win a war. No chemical or biological weapons (high explosives are more effective), humane treatment of prisoners (discourages the enemy fighting to the death), and no killing civilians unless in the pursuit of a military objective (if it's not in pursuit of a military objective, then it's a waste of resources). The goal of the laws of war is to prevent unnecessary violence, not prevent violence altogether. It's a case of "perfect is the enemy of good."