Assume other factors are the same, when a submarine dives, its gravitational potential energy decreases. The loss of potential energy is transformed into kinetic energy which drives the submarine to go faster.
When the submarines goes to surface, there is a gain in gravitational potential energy. The slows down the speed of the submarine.
The situation is similar to riding a bicycle uphill and downhill. The speed of the bicycle going uphill is generally lower than that going downhill, because of a gain/loss of potential energy.