A dynamical phase transition in ferromagnetic granular materials