Ice cream reacts with your saliva and creates a thicker more mucousy secretion which can irritate the back of the throat, so then we try to clear our throat and cough.

Also people that are lactose intolerant are more prone to coughing due to irritations in the throat and lungs.

Cold foods can also cause a "dry effect". When you inhale cold air, which you will if you have a mouthful of ice cream for example, the dry cold air irritates your lungs and tries to get rid of the problem by making you cough, just like if you were outdoors breathing in cold air.