A spin transition mechanism for cooperative adsorption in metal-organic frameworks