In validation phase we care mostly about the general performance of the model rather than the loss. During training phase tracking training loss is very useful to see how the model actually process the data, but what is most important loss is strictly tied to backpropagation and updating weights, thus calculating loss is obligatory for training, but not for validation.
But sometimes if you want to know better how the model behaves under the validation data it is also useful to keep track of test loss.
In the code you provided the only difference is that in

for data, target in test_loader:

you simply load batch (data and target labels) and don’t keep track of the index of the batch, but in

for batch_idx, (data, target) in enumerate(test_loader):

you load batch but also batch index which is sometime useful to keep track of progress or whatnot. You can check why the author went with keeping track of batch indexes simply by looking where he/she used it later in code.
Hope I helped