Thanks for query,
Sex is in our mind & not in organ that is the best example for you.
For getting sexual arousal like erection you need relaxed ,tension free mind having sex in your mind & you succeed to achieve it during masturbation
.But when actually you have to perform it with your perform your mind calculates about it's result so you have tension about it & this leads to this situation.
As you achieve it during masturbation You do not have any disease so don't worry.
You should forget about your performance as it is a game to be played everyday will improve your chances to get erection.