My penis wont get hard for my girlfriend, but is fine when masturbating. Health issue or relationship issue?

Not a health issue. If you are able to masturbate to climax, all the physical parts are working.The question relates to emotional state.Are you and your girlfriend having relationship issues?Have you had successful sexual relationships with another woman? What are your religious cultural beliefs?Have you ever been part of an unplanned preg?Seek prof advice.
Medical? If it works while masterbating likely more an issue with gf. Do you get aroused if she uses her hands? Don't rule medical but if it works while you masterbate maybe it's the type of sexual act that that doesn't arouse you.