Answer: Because electrons are getting transferred from iron to oxygen.
Step-by-step explanation:
Oxidation-reduction reaction or redox reaction is defined as the reaction in which oxidation and reduction reaction occur simultaneously.
Oxidation reaction is defined as the reaction in which a substance looses its electrons. The oxidation state of the substance is increasing.
Reduction reaction is defined as the reaction in which a substance gain electrons. The oxidation state of the substance gets reduced.
For the reaction of rusting of iron, the equation follows:

On reactant side:
Oxidation state of iron = 0
Oxidation state of Oxygen = 0
On product side:
Oxidation state of iron = +3
Oxidation state of Oxygen = -2
Half reactions of oxidation and reduction are:
Oxidation:

Reduction:

As, oxidation state of iron is increasing from 0 to +3, so it is getting oxidized and undergoes oxidation reaction. And, oxidation state of oxygen is getting decreased from ) to -2, so it is getting reduced and is considered as a reduction reaction.
Here, electrons are getting transferred from iron to oxygen. Hence, rusted of iron is an example of a redox reaction