Because the apple is taking the action, the apple is being eaten (accusative). So when
an apple is taking the object, and since we use
der with Apfel (because it’s a masculine noun):
ein Apfel: the nominative form (doing the action); einen Apfel: the accusative form.
Then, we say:
Ein Mann isst einen Apfel. →
ein Mann is also a masculine noun, but in this case it’s in the nominative form, so we said ein.
einen Apfel is in the accusative form.
I hope I helped :)