All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad, sallallaahu ‘alayhi wa sallam, is His Slave and Messenger.
Touching the penis at the end of Ghusl nullifies ablution only and not Ghusl, and it is only ablution which should be repeated in this case.
As far as incontinence is concerned, if one could have, within the due time of prayer, enough time to perform prayer with valid Tahaarah (ritual purity), he will not be of those legally excused. In this case, he should wait until the time when the flow of urine ceases to make Istinjaa’ (cleansing the private parts), perform ablution, and offer prayer with valid Tahaarah. But if he suffers from a ceaseless flow of urine in a way that does not give him, within the due time of prayer, enough time to perform prayer with valid Tahaarah, he is then a sufferer of incontinence.
The same applies if the cessation of urinal flow or the like is irregular in occurrence and time, in a way that does not give him a regular period, enough for him to perform prayer with a valid Tahaarah, then he should perform ablution when the time of prayer is due, and offer with it the obligatory prescribed prayer and whatever he likes of the voluntary prayers. This is so provided that he puts a piece of cloth or the like over his private parts in order to prevent the impurity from spreading, so long as this does not harm him. If something comes out during Thuhr prayer, and nothing comes out during ‘Asr prayer, it is not due on him to repeat Thuhr prayer and both prayers are valid, so long as he has done what he was commanded to do above.
As regards the prayer you have performed without removing the impurity, it is valid according to some scholars who are of the opinion that the one who suffers incontinence even once a day is pardoned for whatever impurity he may have during the day. However, it is better to repeat the prayer to be on the safe side.
Allaah Knows best.