The most common cause of pain during sex is lack of lubrication. You could buy a water-based lubricant at the store and see if that makes a difference.
Also make sure you are relaxed. Being tense is the second most common cause of pain.
Some positions hurt for some women because they allow the penis to hit the cervix. Your cervix actually moves throughout the month. So sometimes it is easier for the penis or fingers to hit it, while other times it is more difficult for them to hit it. So that's another possible reason for why it hurts sometimes and not others. If some positions hurt due to hitting your cervix, there is not too much you can do other than avoid those positions at those times.
When a woman feels pain during sex, she should let her ob-gyn know. The vast majority of the time it's something she can fix on her own by simply relaxing or getting a lubricant, but pain can also be a sign of gynecological issues such as infection.