As James noted, it has to do with the oxidation state of chlorine. If one were to write out the oxidation state for the various atoms, you'd see the following:
+1
-1 .... +1
-1 .... +1 -2
+1 .. -2
+1
. H-Cl ..... Na-Cl ..... H--O--Cl .. (O--Cl)
-
You can see that the oxidation state for the chlorine atom is -1 in hydrochloric acid and sodium chloride while it is +1 in hypochlorous acid and hypochlorite ion. It is this higher oxidation state (fewer electrons associated with the chlorine atom) that have the chlorine be more reactive, technically an oxidizer since it wants to take more electrons from atoms or molecules that can donate them (i.e. that can get oxidized -- an oxidizer oxidizes another atom or molecule). It is incorrect to think of "oxidation" as involving oxygen. Though it can, the term is really referring to the taking of electrons.
In a saltwater chlorine generator, the following happens:
.
-1 .......
0 0
2Cl
- ---> Cl-Cl + 2e
-
Chloride Ion ---> Chlorine Gas + electrons
0 .
0 . +1 -2 +1 ..... +1 -2
+1 . +1
-1
Cl-Cl + H--O--H ---> H--O--Cl + H--Cl
Chlorine Gas + Water ---> Hypochlorous Acid + Hydrochloric Acid
When chlorine reacts with ammonia, the electrons are taken by the chlorine from the nitrogen and the chlorine becomes chloride ion (I show this as hydrochloric acid, but in water this will dissociate to hydrogen ion and chloride ion). I show the oxidation state of chlorine in
red and that of nitrogen in
green.
. +1 -2
+1 .....
-3 3(+1) ....
0 0 ..... +1
-1 ..... +1 -2 +1
3(H--O--Cl) + 2(N--H
3) ---> N-N + 3(H--Cl) + 3(H--O--H)
Hypochlorous Acid + Ammonia ---> Nitrogen Gas + Hydrochloric Acid + Water
So you can see that the chlorine oxidation state went from +1 to -1 and there were 3 of these so a net gain of 6 electrons while the nitrogen oxidation state went from -3 to 0 and there were 2 of these so a net loss of 6 electrons.
When chlorine breaks down from sunlight, there's a complex sequence of reactions (see
this post) that I net out below:
. +1
-2 +1 ..............
0 0 ..... +1
-1
2(H--O--Cl) + hv ---> O-O + 2(H--Cl)
Hypochlorous Acid + UV in sunlight ---> Oxygen Gas + Hydrochloric Acid
So here you can see that the chlorine oxidation state went from +1 to -1 and there were 2 of these so a net gain of 4 electrons while the oxygen oxidation state went from -2 to 0 and there were 2 of these so a net loss of 4 electrons.