I'm not sure what this means - "because I am there"? Are you with him?
His ED could be from anxiety, guilt, an addiction to porn, a physical problem (which always needs to be ruled out when trying to figure out the cause of ED), medication, substance use/abuse - it's a long list.
Have you discussed it with him? Don't accuse, don't try to guess what it is for him, just ask him gently. Take your cues from him, and go from there.
Sorry you found the texts. If he is now being a good guy, sometimes better to not know. But if he is keeping in touch with a prostitute, I'd see that as a problem in trusting him or to be honest, respecting him. Sure this is a good guy to be with?
Libido and erection can be a very mental thing. He needs to go to his doctor first though to rule out anything medical. Doctors are used to discussing this with men. And this is important because things like underlying heart disease, clogged blood vessels, underlying diabetes and as Aunt Jessie says, many medications can cause it as well. Here's more information: https://www.mayoclinic.org/diseases-conditions/erectile-dysfunction/symptoms-causes/syc-20355776. Once the doctor has ruled out any of the conditions known to be associated with impotence and erectile dysfunction, they can then discuss mental health reasons for it. By the way, how old is he?
Here is the thing with porn. Guys are very visual. And masturbating to porn is direct stimulation. It can sometimes then be hard to have that same kind of response when with a live person. Doesn't mean he doesn't want to or isn't attracted to their partner. Most sex psychs will recommend to completely ditch porn and masturbation to try to get back to 'normal' (whatever that is). But this is something excellent to talk to a therapist about.
Try not to take it personally. Although, your man chit chatting with a prostitute he cheated on you with is definitely a no. And this may be a relationship to evaluate if you are getting everything you need from it anymore.
How did you make an assumption that the person he's in contact with is a prostitute?