Spectral Journey: How Transformers Predict the Shortest Path