Reason of phase difference!
Q = CV in a capacitor and \$\dfrac{dQ}{dt}\$ = current therefore: -

I = \$C\dfrac{dV}{dt}\$

This means that current is proportional to the derivative of voltage.

If that voltage is a sine wave then the derivative is a cosine wave hence a phase difference of pi/2 (90 degrees).

In a resistor, V = IR i.e. the relationship between voltage and current is that they are in-phase.