My son used to do this a lot and I just ignored the behaviour and walked away. I know this seems hard especially when they can end up with bruises, but it is a stage that some go through and my son doesn't really do it anymore.