Engineering and imaging nonlocal spin dynamics in an optical cavity