It would depend on damping effects being taken into account or not.
Invoking Newton's 2nd Law of motion, a differential equation for the motion of a damped harmonic oscillator can be written (including an external, sinusoidal driving force term):
$m\frac{d^2x}{dt^2}+2m\xi\omega_0\frac{dx}{dt}+m\omega_0^2x=F_0\sin\left(\omega t\right)$
Where $m$ is the inertial mass of the system, $\omega_0$ is its characteristic frequency, $\xi$ a dimensionless damping factor... And, last but not least, where $F_0$ is the amplitude of the driving force and $\omega$ its frequency.
The stationary ($t\rightarrow\infty$) solution takes the shape $x\left(t\right)=A_0\sin\left(\omega t-\varphi_0\right)$, where $A_0$ is an amplitude factor (whose particular expression in terms of the particular parameters is not relevant to this question) and $\varphi_0$ is phase lag, which is this phase difference you are asking about.
This phase difference can be calculated to be $\varphi_0=\left|\arctan\left(\xi\dfrac{2\omega\omega_0}{\omega^2-\omega_0^2}\right)\right|$. It is a phase lag, so with the (implicitly) chosen phase convention, it has to be positive.
If there was no damping whatsoever in the system, $\xi$ would be zero, and you would be right: $\varphi_0=0$. The stationary motion of the oscillator would be in phase with the driving force (regardless of which is the relationship between $\omega$ and $\omega_0$).
But in an undamped resonant situation the amplitude $A_0$ diverges, which means that the stationary solution is never reached (starting from reasonable, finite initial conditions for the system). Also, in a physical down-to-earth situation, the system would eventually breakdown somewhere, somehow, since energy is being introduced into the system with perfect efficiency (that is what 'resonance' is all about) and without any means to dissipate it. Somewhere, sooner or later, something would go boom or crash. That is how nasty undamped resonances are.
On the other hand, for a non-zero damping, in the resonant case $\omega=\omega_0$, the argument of the $\arctan$ function diverges, so the phase difference turns out in this case to be $\frac{\pi}{2}$.
To sum up, the $\frac{\pi}{2}$ phase appears as an effect of damping in the system, and just a little bit of it is enough to offset the oscillatory response from the system. As it happens, every realistic, down-to-earth harmonic system has some kind of damping in its dynamics. Even if the damping is so small that the induced dephasing in an out-of-resonance situation is negligible for every purpose that the model has, damping has to be taken into account in resonant and closely resonant motion, otherwise the model yields highly unphysical results.