Electrolysis is a process where electricity is passed through a solution and this results in the molecules of the solvent and the solute getting separated into ions. Once ions are formed, the same ions combine with each other to form a gas or different ions with opposite charges combine with each other resulting in the formation of different compounds.
Electrodes are essential for electrolysis as the current enters the solution through one of the electrodes and returns through the other.
When ions are formed during electrolysis they can combine with the substance that the electrode is made of and cause its degradation. For example, if the electrodes used in the electrolysis of water are made of iron, copper, etc they form hydroxides with the OH- ions that are created. Electrodes have to be able to resist this corrosion if electrolysis is to continue over a period of time. Metals like platinum can be used as electrodes but they are quite expensive. A cheaper alternative that is resistant to corrosion is graphite.
As graphite conducts electricity and is resistant to corrosion it is used to make electrodes for electrolysis.