Stable and unstable capillary fingering in porous media with a gradient in grain size