Not illogical at all. A person that abuses animals is a potential menace to society - lack of empathy means they might easily abuse humans too. We are punishing sociopathic tendencies here.
Farming animals is not sociopathic, it's a business decision based on economic interest.
This works because animals don't have human rights. (Obviously.)