The human brain allows us to compartmentalize and deal with such things that way.
I raised mice for my snakes.
I gave them comfortable housing, quality food, stuff to play with, forage, housed with other mice... but they didn't have names and were not pets.
Once the time came to do the deed and cull the feeders/select the next generation breeders, I viewed them as food for my snakes and my selection criteria was size based, and also temperament based - so I would not breed from mice that were nervous or aggressive at being handled, I would not breed again from mice that were not good parents.
It is not fair, or indeed accurate to say that I did not view them as living breathing animals, of course I did, and I cared about them during the course of their lives - breeders would spend their entire natural life span with me.
On the other hand once it came to cull day, I didn't find it particularly hard to view them as food for snakes or replacements for the breeding population.
I chose to do this as the trade in frozen rodents is pretty horrid, with them being intensively farmed and culled in large groups in not particularly humane ways, and I did not wish to contribute to that.
At the same time I had pet rats, and I could not have killed one of my rats to feed one of my snakes - they came into my home as pets and remained as pets their entire lives.