A transformer works on the principle of electromagnetic induction (Faraday’s law of induction) .
The law states that an ElectroMotive Force (EMF) is generated in a coil when it is placed in a changing magnetic field that passes through the area enclosed by the coil.
So, it is clear from here that we need a hanging magnetic field.
When we use DC sources, the magnetic field produced by a DC current is uniform and does not change. Whereas, if we use it’s counter part (AC source), the current changes (let it be direction or value) with time and thus, a varying magnetic field is produced.
Ultimately, a transformer cannot work on DC because, the primary coil will create a uniform and constant magnetic field, which will fail to induce EMF in the secondary coil.
Note that when you will switch on the source, the current in the primary coil will change from 0 to a specific value (this happens in a moment). Thus, the magnetic field will change from 0 to a specific value in a moment and an EMF will be induced in the secondary coil momentarily. Just momentarily and nothing after that.
I hope this helps you.
[originally answered by Rajat Rathi on Quora]