One of Yakul's AI Packages, specifically the WAC one, affects whether you have your weapon drawn and if you're in combat or not. He should not follow you if you have a weapon drawn even if you're not in combat.
I haven't yet had him turn on me because if I know there's going to be a fight or if I start one, I draw my weapon and he stays where I leave him until I sheath my weapon and then he will come to find me. If I'm ambushed unawares though Yakul will fight the enemy because he has high confidence. That doesn't happen very often because I have other creature companions who are more aware than I am at times.
Yakul has the Horse PC Faction and I've had my horses turn on me if I hit them by accident, so this may be a reason he's attacking you. Although as I said he shouldn't be in a fight if you leave him a distance away by drawing your weapon and then going to the fight, which is not always possible though. I haven't actually tried hitting him so he hasn't turned on me.
One thing you could try is to give him the Player Faction or to make him Player Owned. To do the latter you will need to load Sweetwater Camp and Yakul in the Render window and double click on him. Then select the ownership window and choose Player. Then he won't attack you no matter what you do.
You may or may not have to remove the Horse PC faction otherwise they will probably contradict each other. I have a mod of my own with a horse in it and he only has the Player Faction as well as being Player Owned, and it works just fine.
I've also made my Yakul Essential because I use other mods that have very hard creatures besides WAC, (Elsweyr the Deserts of Anequina for one) and if he decides he wants to fight, and he often does even if he's supposed to be waiting, he dies despite having high health and I have to reload because I don't want him to die. That's my choice though as I'm quite taken with Yakul.