There are a couple of things you can say like
Your pet was lucky to have you.
This is how you can remind them that how great they were at taking care of their pet. This might help them get over the grief. (Source)
You can also try saying that their pet had a great life because of them. For this, you can remind them some great events they had with their pet. Though it's not compulsory, you can try it. There is only one setback of this. Some people might, but not every time, mourn over this too much after you remind these events.
Once my neighbor lost his pet and I tried reminding how much fun he had and how great he was at taking care of their pet. This helped and he said thank you.
If someone lost their pet due to some illness, they might be feeling the guilt of not taking the pet to a vet on time. In this case, you can say,
You did everything you could do.