Not exactly.
Two issues: first, minimizing the suffering of the innocent is the way to wage just war; second, proportionality is a consideration when targeting and civilians may be hurt.
What is the military gain when compared to the suffering to the innocent. That is a key question that is asked.
Therefore, not all “enemy flagged” ships are a legitimate target.
What is the military gain when compared to the suffering to the innocent. That is a key question that is asked
The problem is: how is a submarine commander to determine this? Or, for that matter, a bomber pilot or an artillery officer?
As I recall, every belligerent in WW II operated on the principle of "Unrestricted Submarine Warfare" -- which presumed that an enemy-flagged ship operating in a war zone was carrying military personnel and/or materiel. And, was, thus fair game. The only exception was hospital ships -- which were painted white and adorned with a red cross.
Civilians traveled thereon at their own risk...and were warned accordingly at the ports of embarkation.
At the same time, though, the principle of "Unrestricted Submarine Warfare" was a murky area within the international laws of war. Recall the >Lusitania incident in WW I. For that reason, I recollect that WW II public dispatches never identified submarine captains or crewmen by name.