The general rule is that civilians are protected persons in military conflicts. But civilian casualties can be excused if associated with military necessity.
I can easily imagine a situation, in which a civilian is an accidental witness of a covert military operation. They can not be detained, as that would require delegating a soldier (or more) to guard them, which may jeopardize the operation. And leaving them free definitely jeopardizes the operation, as they may inform their military.
Does such a civilian witness constitutes a legitimate military target?