A submarine is supposed to be invisible to all units except other submarines and destroyers. I'm not sure what the intended behaviour is, but submarines are visible to cities. If they are within a few tiles of cities the ai's city and other units can target them, including archers and frigates. Even though they are invisible moving them into another civ's territory when you don't have a open borders agreement would cause you to declare war. Again i'm not sure if this is the intended behaviour or not. It was originally like this in Civ4 but was later changed to be allowed without declaring war. Submarines are also noticed by city states as trespassing in their territory when they should have no means of detecting them. I'm not sure if these are bugs or just behaviours that don't mesh with how submarine's behaved in civ4.