Why when I pull back my foreskin and touch the penis it hurts?

Balanitis, phimosis. Tight foreskin means that smegma can collect under the skin and irritate the glans. Inner surface of foreskin and glans can also get inflammed. A tight frenulum, between foreskin and glans can also be painful. Your foreskin should retract easily, otherwise suggest you consult a urologist. You might benefit from 0.1% Betamethasone cream applications or a circumcision or prepucioplasty.