The depth axis by convention, and stacking order on a flat surface. A named direction rather than a thing.
The letter descends from Greek Ζ (zeta); an early version stood in the oldest Latin alphabet, was dropped as the language changed, and was later borrowed back from Greek to spell Greek loanwords, keeping the name zeta unchanged. As the third of the Cartesian unknowns it completes the sequence x, y, z that Descartes fixed in La Géométrie (1637) — three letters standing in for whatever is not yet known, regardless of how many dimensions are actually needed.
The third axis, reached for only once two were not enough to say what needed saying — depth, and which layer sits above which on a flat surface. A picture that stops being flat needs its own letter for what recedes.