Really interesting question.
Short answer
Index is not stored anywhere. Its value (i) is just reflection of the structure of the array that is being processed within your code.
A little longer answer
From d3 docs for selectAll()
The elements will be selected in document traversal order (top-to-bottom).
This means that function transitionSheet() will always restore the order as it is in DOM tree.
However, in sortSheet(), after selection, data rebinding is performed with the call to data(). That causes changing order of elements in the array (but not in the DOM tree, which allows subsequent call to transitionSheet() and the effect of restoring original order)!
In conclusion, you can view index i just as a temporary artifact, related to the array that you manipulate in your code at given point, not as a "property" of the data.