The first question is whether retributive justice is ever morally justified or whether all justice should be restorative and preventative. In other words, one needs to consider one's purpose in responding to criminal acts. Morally, the notion of retribution is problematic because it means that people claiming to be "just" are acting in a manner that is cruel and vindictive to others. This not only creates a cycle of vengeance, but also harms the ethical nature of the people involved in the criminal justice system by making them instruments of harm to others and spend their time considering "punishment."
Instead, it would be more morally just to think about two other issues, prevention and restoration. In terms of prevention, it is important that pedophiles do not molest other children. Psychotherapy, drug treatment, and various forms of monitoring are important steps to prevent pedophiles from re-offending, as is incarceration. As pedophilia is increasingly understood to be a fixed sexual orientation, any treatment should involve some form of lifetime monitoring and counseling. This can help and support both the pedophile and the surrounding community.
A second form of justice that is important is "restorative." Since a pedophile has harmed children, the pedophile should be responsible economically and socially for undoing that harm. That might mean, for example, being required to pay the costs of all medical and psychological treatment for the child and doing extensive community service.