When HCl is dissolved in water, it dissociates into H+ and Cl- ions. These ions are free to move in the solution, and they can carry an electric current. When an electric current is passed through a solution of HCl, the H+ ions are attracted to the negative electrode (cathode), where they are discharged and form hydrogen gas. The Cl- ions are attracted to the positive electrode (anode), where they are discharged and form chlorine gas.
The overall reaction for the electrolysis of HCl is:
2HCl(aq) → H2(g) + Cl2(g)