My toddler was aggressively hitting the dog

I don’t know what to do, he’s 2 years old.

I was walking from the kitchen and saw him aggressively hitting my boyfriends parents dog repeatedly in the head.. I don’t know where it came from.. I don’t know if he’s acting this way because I’m pregnant (28 weeks) or what..

He’s usually a sweetheart to animals. He loves dogs, I just don’t know what’s going on.