Please help I’m at my wits end

My 3.5 year old is handful.When he is in good mood you can talk with him like adult ,he will play with his baby brother ,he will sing and hug his brother and show him correct way /direction for whatever little one doesn’t do correctly.He knows colors numbers abc shapes and he is visual learner.But when he is mad scream yell hit him self in the head and scratch so much you will see marks afterwards.Sometimes yelling will be if my mom just look at him but sometimes he will play with her and you would never guest he can be mad at her.Now we visited his aunt and his behavior started:my mom was playing with dog “grandma don’t play with dog,don’t talk with aunt,don’t don’t don’t”,and od She replays to him hitting and scratching starts.

I tried to explain what he does it is not good how that will hurt him later but like talking to wall he is so in his emotions there is no way to explain.

Help what to do?!!