Understanding Privacy Risks in Code Models Through Training Dynamics: A Causal Approach