Hello and hope you are doing well.
You cough or gag, when you clean your ears is because of the nerve supply. Two nerves which are actually branches of one big nerve, the vagus supply the ear and throat. So, when the ear is cleaned, this transmits impulses from both the throat and the ear canal, triggering the cough/gag reflex. This is normal.
Hope this helped and do keep us posted.
It's not a good idea to clean the internal part of your ear with a Qtip or anything else that enters the ear canal - you could accidently puncture your ear drum - or at the very least, using a Qtip inside the ear canal actually pushes the ear wax and "gunk" farther down into the ear and can get it impacted.
However, the gag/cough relfex you're feeling when you do that is perfectly normal. have you ever noticed it happening when you're at the doctor's office and they look in your ears with teh little scope? I do all the time - it's quite annoying. I don't know the exact medical reasoning for it, but I believe it has something to do with irritating the eustachian tubes.
Seriously, though - please try to find a better way of cleaning yoru ears than sticking Qtips into them - you certainly don't want to end up permanently damaging your ears and hearing. Remember the old saying "Never stick anything into your ear smaller than your elbow"! There are some over the counter drops that you can buy that you put in your ears and it helps to loosen and soften the wax and then you kind of let the warm shower run against your ear and it will help wash it all out. If nothing else, your doctor can clean your ears out for you wiht a special instrument.
Best of luck!