Anything and everything was, well, if not necessarily "fair game", at least "game".
In any event, an enemy-flagged ship sailing in a declared war zone (which the Baltic certainly was) was presumably (almost certainly) carrying military personnel or material.
As, indeed, the Wilhelm Gustloff was doing.
The loss of civilian life was regrettable but one of those so-called collateral costs of war. In fact, the Soviet submarine commander probably didn't give it a moment's thought.
If the Soviet commander was aware of what the Axis had done in the USSR (I don’t know what was concealed from them), I’d think he couldn’t care less about the civilians.