It does not know. It backpropagates whatever result is. You don’t selectively backpropagate depending on if loss if better or now, in fact, that would be impossible.
Realize that, in the early stage of training, network havent seen any data. For 1st iteration, loss will decrease (ideally), for the 2nd one, data may be otally different, thus, higher loss, but you need to backpropagate in order to keep learning.
When you backpropagate you compute gradients and error for whatever your loss is.