Why is it bad for you to drink milk when you're having gastric pains?

Depends. Depends of the cause of the pain. Milk can under some circumstances diminish the gastric acidity transiently and if the pain is caused by acid irritating an ulcer, temporarily relieve it. The best response would be, find out what is causing the pain.