My son does this too. I just consantly am telling him not to hit and redirecting him when I see him about to hit someone. He knows exactly what he is doing too. I sometimes think he does it for attention.
If someone else has any ideas, I'd love to hear them too!