Why does the doctor ask you to "turn your head and cough", you ask? So that he can test you for a hernia. But that's the simple answer. The harder answer is in two parts.
Part One: Why the cough?
When you cough, a vibration will run down your spine. Based on how this vibration gets transmitted down to the base of your spine, which is what the doctor is touching underneath your testicles, will indicate whether or not you have a herniated disc in your spine.
Part Two: Why must I turn my head?
I've heard two explanations for this. One is that the twisting of your neck will tighten up your spine and improve the accuracy of the doctor's diagnosis. I call this the practical explanation. I've also heard a more utilitarian explanation: do you think the doctor really needs you to cough on him? No, thus you are asked to turn away from him before coughing.