Parent pointers let you reconstruct paths and cycles, not distances. Always track parents when you need to output the actual path or cycle. Walking back steps guarantees you land inside the cycle, even if the improved node is outside. This is because any path with edges in a graph with nodes must repeat a node.
This double-walk technique works because the parent tree contains the cycle. The first steps ensure you enter the cycle, and the second loop extracts it.