If the field were uniform there would be no net force on the atoms and thus no separation of the quantized spin orientations. (Think of the atom as being a magnetic dipole. A non-uniform field exerts a different force on each "pole", thus giving the atom a net force depending upon the orientation of the dipole.)
Stern and Gerlach used neutral particles: hot silver atoms from an oven. Lorentz force (experienced by atoms) due to an eventually uniform field should be globally zero. So the net force acting on atoms must be another: atom is a coil-like system and what they did is to dealing with it as with the induction coil you find in an analogical multimeter.
You obtain a force just for a non-null derivative of magnetic induction, that is F=gbB where:
g is the coupling constant between angular momentum and magnetic dipole momentum
B is your field
b is there because I supposed B=a+bz along the non-uniform axis.
Stern and Gerlach knew the presence of an magnetic momentum for atoms also before the experiment, but they obtained its quantization by showing it with astonishing facts!