It shouldn’t hurt when you retract your foreskin. Possible reasons that it may hurt include adhesions (scar tissue formed between the foreskin and the glans penis) or a skin infection under the foreskin.
Occasionally the foreskin can get stuck in the retracted position, which can be very painful and should be evaluated immediately as it can cut off blood supply to important parts of the penis. All of these possibilities need medical attention and you should see your health care provider if you have any pain with foreskin retraction.