Please explain this circuit (CNY70, Zener diode)
There's a very good reason you can't figure out how the circuit works: you're not showing the entire circuit. Please edit your post to provide either a link to the circuit, or an explanation of how it was produced.

To begin with, with 5 volts in and a 22 ohm resistor, the current through the LED will be in the neighborhood of 150 mA, and it's only rated for 50 continuous. This suggests that the input voltage should be less than 5 volts.  Voltage across the resistor is Vin - 1.6 (the forward voltage), so you can figure the current through the resistor by Ohm's Law. For a current limit of 50 mA, this means the input voltage should be roughly 2.5 volts.

Secondly, the circuit ground is probably connected to C rather than E, with the output connected to E rather than C. 

Finally, there will be somewhere (maybe back at the unit the 3 wires attach to), a resistor from the output (E) to +5, with a value of about 5k or more.

When you connected 24 volts to the input, if the zener did not die it protected the the LED by limiting the voltage to ~4 volts. This is still too high, but it's clearly intended for short-duration overvoltages.