This weird stage is really common, and mostly developmental-- something that most babies will naturally outgrow. It's upsetting and gross, but not harmful. The baby won't actually choke or cause injury by occasionally over inserting fingers in the mouth.
My son did it for a couple weeks at about that age, and it's recently had a brief resurgence (age 2). Some reasons that babies/toddlers do this:
Trying out something new. They have discovered a new sensation and a
new thing their body can do. Some kids are determined to investigate any
new discovery fully, even if it's somewhat unpleasant for them.
(Teeth grinding is another common example of this). Some kids oddly enough seem to find the dramatic reaction of their own bodies, and any nearby adults, hilarious.
Getting a reaction. "When I do this, parents look panicked and drop
whatever they're doing to rush right over!" This can be either an
attention-getting technique, or just an experiment with cause and
effect, an extension of 'trying out something new'. A nine month old
can't actively/maliciously manipulate, but can notice 'when I do
this, something that I like happens, I should do this more'. If is common for gagging to increase when the baby is bored or asking for attention when you are unable to provide it.
Teething. Chewing on hands is a classic teething sign, and it's
definitely possible for a kid to overdo it and gag themselves. If back teeth are coming in, and it's not impossible that the 1-year molars are already starting to move, then pain relief or cold teethers with a good shape to reach the back teeth without gagging might solve the issue.
Rarely, it can be related to silent reflux, chronic nausea, food
allergy or other digestive and stomach disorders. Even a baby can
make the connection that the upset stomach feels better after
vomiting, and may make a habit of it after accidentally discovering
the connection. This is much less often seen than the other
possibilities, but since it's been going on somewhat longer than a
usual baby phase, may be worth considering.
If it's purely behavioral, you will probably have best results with just redirecting, and trying not to give a horrified or dramatic (and thus rewarding) reaction. Keep your little one's hands busy with teethers, toys and other things that are safe to put in the mouth (and preferably don't have the shape that allows them to gag themselves with the toy. I had to remove a long-legged giraffe shape teether from my son for exactly this reason). Try not to respond to the coughing with a lot of sudden concentrated attention or panic, which are interesting and rewarding to a baby. Make sure your baby is getting plenty of focused, playful attention, and encourage babbling and calling to you (vs acting out, screaming or coughing) as a way to engage you.
Punishment like slapping is not appropriate for a baby so young, as even if they learn that something isn't good to do or desirable, they don't really have the planning ahead and impulse control ability to actually not do the thing. You are better off just preventing the behavior, reducing how rewarding or entertaining it is, and waiting for him to outgrow it.