It's a mental thing. Might be easy to fix with just some more play or relaxing talk. Tell him you wanna try putting on the condom and then NOT having sex - you wanna tease him for 4 hours or something. Then the mental block of "now we're going to" is not going to be in his head. Make him know that full sexual performance is not required ALL the time, every time.
You would want it the same - some days you'll want different things - even to play around and not have full sex.
But it's most likely a common, normal thing - although it's not easy to figure out. It's a mental issue that controls his hardness - and he can't actually WILL IT to stay up or down. It's kinda a subconscious thing. Maybe he's privately afraid of close personal contact, or what it means to have a serious girlfriend and maybe kids. Lots things - if it keeps on, try to make him ok with it - talk about it and how you WANT TO work on it so he's happy. And you're happy.
If it still happens, he can talk to a counselor, they can show him how this is common ALL the time and how to work it out!
Information on this site is provided for informational purposes only.
It is not meant to substitute for medical advice provided by your physician or other medical professional.
If you have or suspect that you have a medical problem, promptly contact your physician or health care provider.