I'm not a doctor, but it doesn't sound like ed since you can get and maintain an erection until the condom comes into the picture.
Lots of guys go limp when it's time to put the condom on. Even if you don't think that you're worrying or thinking about the condom, somehow your subconscious is, you know?
As long as you can get an erection and keep it until you cum any other time... Like masturbation or oral sex... Then physically you are functioning fine, if that's the case, then yes, it's all in your head.