If the sub moves in combat movement it attacks, but:
Step 2. Submarine Surprise Strike or Submerge (Sea
This step is specific to attacking and defending submarines.
Before the general sea battle takes place (steps 3–5), both
attacking and defending submarines can choose to either make
a Surprise Strike die roll or submerge. A player may choose to
submerge all, some, or none of his or her submarines.
If the sub moves in non combat movement:
Sea Units: A sea unit can move through any friendly sea
zone. It can’t move into or through a hostile sea zone.
Unlike other sea units, submarines can move through and
even into hostile sea zones in the Noncombat Move phase.
However, a submarine must end its movement when it enters
a sea zone containing one or more enemy destroyers.
Sea zones being made hostile:
Sea zones are either friendly or hostile. Friendly sea zones
contain no surface warships (this doesn’t include submarines
and transports) belonging to a power with which you are at
war. Hostile sea zones contain surface warships belonging
to a power with which you are at war. (The presence of a
surface warship belonging to an enemy power with which
you are not yet at war doesn’t make a sea zone hostile).