Electrolytic capacitors have 2 terminals of different length to indicate polarities, but ceramic capacitors have terminals of same length having no polarities. Why is there a difference between these two types of capacitors?
Electrolytic capacitors will only work if they are connected the correct way round in a circuit. They are polarised, i.e. they are sensitive to the polarity of the applied voltage; the + connection of an electrolytic capacitor should be at a higher voltage than the - connection.
So the component needs to carry that information clearly. One of the mechanisms used is to have wires of different length, so that it is easy to get correct when using the component to manufacture something.
Ceramic capacitors are not sensitive to the polarity of the applied voltage, it doesn't matter which connection is more positive than the other. Hence there is nothing to indicate. Hence there is no need to have wires of different lengths.
Edited to incorporate helpful comments. The issue is for electrolytic capacitors is the voltage polarity across pins.
(Of course, adding wires of different length might cost a tiny bit more for the manufacturer, so they wouldn't want to do that for no reason :-)
The construction of electrolytic capacitors makes them polarized because of the use of a paper soaked in electrolyte. As this polarization must be clear to the user, electrolytic capacitors have polarity markings on the case and different length leads.
Reversing the polarity can cause overheating and even explosion due to failure of the dielectric.
See this informative article for more details.