Why a gradient is needed for a net force.

If a diamagnetic substance is located in a uniform magnetic field, then the repulsion from each direction will be equal and there will be not net force on the substance. This would also be true for a paramagnetic or ferromagnetic substance and for a permanent magnet, but in those cases the attraction would be equal in both directions.

In the diagram below, the field between the permanent magnets will be most uniform if they are very tall and their faces are parallel and close together.