Did you ask your teacher why you can have 'a headache'?
Actually you can have 'a stomach ache' or 'stomachache'. Some types of pain go with or without the indefinite article. For instance you have 'earache' but not usually 'an ear ache'. Also you almost never have 'a tooth ache', but always simply 'toothache'.
Basically, if you split the expression into two words, you must use the article. When it is one word, you sometimes use the article, and sometimes do not. (As with 'a headache' and 'toothache'.) However, you can use either 'stomachache' or 'a stomach ache'.