Because a caterpillar is a heterotroph and it cannot make its own food so it relies on the energy in plant sugars and by eating plants it gets energy from the sun in an indirect way. So to put it simply, the caterpillar uses light captured energy for energy.