Sorting ultracold atoms in a three-dimensional optical lattice in a realization of Maxwell’s demon