Priapism is a medical condition for people with penis experience a persistent and sometimes painful erection that is not caused by sexual stimulation and is erect for more than 4 hours. However, if a penis is erect for more than 4 hours without sexual stimulation, it is considered a medical emergency and if left untreated, can lead to erectile dysfunction.
Sources:
https://www.mayoclinic.org/diseases-conditions/priapism/symptoms-causes/syc-20352005
https://my.clevelandclinic.org/health/diseases/10042-priapism