It's hard- my LO doesn't head butt, but (lol) she's learning more how to rough house (coudln't think of a better word for it?). We aren't rough with her- but we actively play often and lift and tickle and grab and roll around etc... she loves it, but sometimes she'll think she's being funny and smack my face or something similar... I just always make sure to take a moment and say (firmly) "hitting in the face is not Ok"- then we move on. I really have no other great way to deal with it- I do the same if she throws hard toys or things at me etc... lucky she's never done this to anyone else (yet).
Sometimes though, in the moment, it's hard to be too serious and a giggle might pop out- which, of course, only encourages them to engage in that type of behavior.... and maybe that happened once when my LO was younger? I can't remember. All I can do is be consistent now. If I need to block her hand I do- then redirect her onto something else. If the behavior doesn't stop (after that first warning)- then play time is over for a while.
Sorry- no great advise!