Unlocking the Power of Rehearsal in Continual Learning: A Theoretical Perspective