The loss in a transformer is due to a variety of real-world factors such as non-zero DC resistance in the wiring. Quoting from (what else!) the Wikipedia page,
For simplification or approximation purposes, it is very common to
analyze the transformer as an ideal transformer model as presented in
the two images.[5] An ideal transformer is a theoretical, linear
transformer that is lossless and perfectly coupled; that is, there are
no energy losses and flux is completely confined within the magnetic
core. Perfect coupling implies infinitely high core magnetic
permeability and winding inductances and zero net magnetomotive
force.[6][c]
Deviations from ideal The ideal transformer model neglects the
following basic linear aspects in real transformers:
a) Core losses, collectively called magnetizing current losses,
consisting of[17]
Hysteresis losses due to nonlinear application of the voltage applied
in the transformer core, and Eddy current losses due to joule heating
in the core that are proportional to the square of the transformer's
applied voltage. b) Whereas windings in the ideal model have no
resistances and infinite inductances, the windings in a real
transformer have finite non-zero resistances and inductances
associated with:
Joule losses due to resistance in the primary and secondary
windings[17] Leakage flux that escapes from the core and passes
through one winding only resulting in primary and secondary reactive
impedance.