Most likely because in first case:

You collect loss.item() which by default already averaged to a batch size
and later you average it by number of samples in the full epoch len(y)


and in the second case you:

append all loss.items() to the list
average it by the number of items in the list np.mean(all_loss)


Second way, I suppose gives a correct result. To correct the first case, you need to average by the number of batches  train_loss / len(iterator). This way results should be equal, I guess.
To summirize: len(y) from the first case is not equal len(all_loss) in the second case.