The optimality condition is necessary for distTo[u] to be the minimal length of paths from s to u.
If
distTo[w] > distTo[v] + e.weight() for some v, w, and edge
v-> w
The path from s to v followed by the edge from v to w would have total length
distTo[v] + e.weight()
And so dist[w] would not be a minimal length for a path from s to w.