Causal Discovery and Forecasting in Nonstationary Environments with State-Space Models