Underwater localization is one of the key techniques for positioning, navigation, timing (PNT) services that could be widely applied in disaster warning, underwater rescues and resource exploration. One of the reasons why it is difficult to achieve accurate positioning for underwater targets is due to the influence of uneven distribution of underwater sound velocity. The current sound-line correction positioning method mainly aims at scenarios with known target depth. However, for nodes that are non-cooperative nodes or lack depth information, sound-line tracking strategies cannot work well due to non-unique positional solutions. To solve this problem, we propose an iterative ray tracing 3D underwater localization (IRTUL) method for stratification compensation. To demonstrate the feasibility of fast stratification compensation, we first derive the signal path as a function of initial |grazing angle, and then prove that the signal propagation time and horizontal propagation distance are monotonic functions of the initial grazing angle, which guarantees the fast achievement of ray tracing. Simulation results indicate that IRTUL has the most significant correction effect in the depth direction, and the average accuracy has been improved by about 3 m compared to a localization model with constant sound velocity.