Ruling represents setback for investigation that targeted state Democratic officials who criticised immigration raids.