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 is His slave and Messenger.
There is no contradiction between the statement that the prayer with a Ghusl (i.e. a ritual bath) in which one intended ablution is valid and the statement of not touching the private parts in this Ghusl. That is because a person who performs Ghusl first intends Ghusl and ablution and then he starts by washing his/her private parts and then washes his/her body without touching his/her private parts again. What is important is that he should not do something that invalidates ablution after having started to perform Ghusl. Therefore, if the situation is as you mentioned in the question that you touched your private parts while performing Ghusl, then the prayer is not valid with this Ghusl because you should have performed ablution after it according to the view of the majority of the scholars because they consider that ablution is invalidated by touching the private parts.
However, if you follow the Hanafi School of jurisprudence who are of the view that ablution is not invalidated by touching the private parts, then your prayer is valid and you are not obliged to repeat it. Nonetheless, it should be noted that some scholars who are of the view that ablution is invalidated by touching the penis (private parts), they are not of the view that you should repeat the prayer in your situation because the Prophet did not order the companion who did not know how to perform the prayer properly to repeat it (i.e. the previous prayers which he had performed before).
Allaah Knows best.