Any suggestions to make it stop??

Sooo my almost two year old will smack himself in the head when he’s upset or frustrated. Mostly when he is playing with another child and they try and tell him no and take away a toy he was playing with. Or when he is getting in trouble from misbehaving he will smack himself when I say he cannot have a cookie as it’s 5 am.

Anyways does anyone know how to get him to stop hitting himself?!? He doesn’t get spankings or anything as I don’t agree with hitting children. I have tried to whole “ouch we don’t want to hurt ourselves” The “ we want to be nice to our bodies it’s not nice to hit” I’ve tried the holding his hands away from his head saying we need to have nice hands to ourselves. I have kinda lately just excepted it as a behaviour hoping he’ll just outgrow it but you know someone’s always gotta say something..

my mom has just called me saying she’s worried about him hitting himself and him covering his ears when

1. he either just doesn’t wanna listen to you

2. He doesn’t know who you are and instead of trying to listen he gets scared and just covers his ears

3. the place is far too loud

4. You’re someone he doesn’t know trying to give him discipline.

She’s making me feel like there’s something wrong with my little boy🙁

Mind you this kid is only almost 2 he can tell you all his body parts and point to them. He can take off his own clothes, tells you when he needs a bum change, cleans his own messes up off the floor if prompted too, can say full sentences, can put his own shoes and boots on (on the right feet) and more in my mind he’s advanced in a lot of things. The kid was born just before the pandemic he doesn’t see my side of the family much as they choose not to come around or always make excuses he doesn’t even know who my mother is she’s just some strange lady that comes around maybe every 3-6 months for 2 hours with most of the time a new toy to make up for never being there …