Iron is made up of atoms. As we know that, heating creates space b/w those atoms, while hammering allows to shape the piece of iron. If we do not heat and then hammer, then it would change shape, but, it would take time.
Heating allows the iron to quickly take shape by the force applied.
The force applied by hammer changes its shape.