Back of my head hurts wen I cough like its going to explode. Gp gave me muscle relaxants and it works. Y does it hurt? Its my first tym to exprience it

Muscle Tension. What you are describing is muscle tension or a pulled muscle which got stretched when you started coughing or have a pinched nerve that is arising from the first two cervical nerve roots that are causing the problem. You may have slept wrong and have a mild stiff neck. If persists, discuss this with your doctor.