Why does my erection all of a sudden stop?

There are many. Reasons why this could be the case, but without more information about when this started, what exactly is happening(as in are you readily able to get an erection but then it becomes flaccid in the process of intercourse), and your health history is a bit difficult to better guide you. Consider a formal HealthTap Prime consultation for better guidance or just reviewing this with your PCP.
Probably psychologic. Your erection can stop suddenly if the doorbell or phone rings and you are going to answer it. Can occur if you are making love and a child suddnly appears in the bedroom, etc.