You could create a custom Dataset and return the index with the data and target tensors in the __getitem__ method. To do so, take a look at this tutorial and or override the MNIST dataset with your custom __getitem__ implementation.
I think the best approach depends on your actual use case.
If you want to get the index used to load the current sample, I would write a custom Dataset and just return it. This would avoid any issues with using another sampler or any kind of shuffling etc. since the index will be directly returned. On the other hand, if you are more interested in the sampler indices for a particular reason, you might want to check its implementation or write a custom one etc. (in that case I’m not sure I understand the question correctly).