It is important to note that although penile erection is an important component of male sexuality, it is not the only one.
When we speak of “impotence,” we are saying that this man can not, when in fact the limitation in erectile function does not limit him regarding other sex-erotic alternatives that are very pleasurable and even orgasmic. Instead of “impotence” I will use the term “dysfunction” or “difficulty” erectile.
Now, I start by presenting some necessary information about erectile dysfunction.
It can define as the inability to achieve or maintain a satisfactory erection to enable intercourse (penile penetration of the vagina). In 90%, erectile difficulties respond to organic causes that affect the functioning of the erection process; however, many psychological variants can also cause such dysfunction.
Remember that sexual activity requires that the body and mind work as a team.
Sexual desire is born in the brain, and this mental process leads to physical responses of the nervous and circulatory systems, essential for the erection to occur. If there is damage or blockage at any stage of this process, the erectile response may be affected.
Your case appears to be one of psychological origin, particularly because it is something that does not always happen to you and, specifically, because it only happens in very specific situations: when you are holding extramarital affairs. It is known as situational erectile dysfunction.
One of the most common reasons for a man to experience erectile difficulties of psychological origin is sexual guilt. Yes, incredible but true. You are exhibiting a symptom of your guilt-trip for having been misbehaving. The unconscious “I” of a man can exhibit his feeling of guilt through a failure in erectile function despite the fact that the man, consciously, has decided that he wants to be unfaithful. To this, you have to add any feeling of anxiety, stress, and fear that may be part of the experience. All are frequent causes for erectile difficulties.
I invite you to evaluate your marriage situation well. Many people think that infidelity occurs as a consequence of the fact that the sexual life of marriage is not going well. It is a myth, And your situation makes it obvious. Infidelity, rather, occurs as a consequence of some crisis in the effective and emotional relationship of the people involved.
A “good and stable” relationship, as you describe yours with your wife, does not usually lead to acts of infidelity. Be your goal to define and solve what is happening in your marriage, or simply manage to manage the feeling of guilt that is surely causing the erectile difficulty, I think the best thing you can do is seek professional psychotherapeutic help