French resistance assassinated plenty of German soldiers, including shooting them in broad daylight on the streets of Paris. It got to the point that German soldiers were ordered to never walk the streets alone while in uniform.
Technically, they weren’t “at war” since the Occupied Zone of France was under German military rule. Which meant that legally, on a local level, the war was over and the Resistance were civilian terrorists attacking the legal occupiers of the territory.
However, the Resistance’s legal argument was that the “real” gov’t of France was the Free French gov’t-in-exile based in London, and that the Resistance was acting legally in resisting the German occupation, and that therefore assassinating German soldiers was legal.
When the Germans were chased out of Paris by a combination of the Free French Army and the Resistance, members of organised Resistance groups were declared to be legal combatants and part of the Free French Army. Just to make it legal and all. So, as it turned out, the Resistance assassinating German soldiers on the streets of Paris had been legal all along.
Yes, they did have lawyers at the time working out this stuff - it’s not enough to just say “we’re at war” - there has to be a legal framework behind it.
If the German military had stayed in charge of the Occupied Zone, then the Resistance would have been acting illegally, and the Gestapo - who were a branch of the German Police Force, not a military organisation - would have been able to do what they did completely legally.
So, while history isn’t always written by the victors, they can and do re-write the laws so that whatever was done by their own side was completely legal and whatever was done by the enemy was totally illegal.
Getting back to the OP, I’m 100% certain that any American who assassinated Osama would have the best legal defence available, and that any punishment he eventually got would be of the slap-on-the-wrist variety.