Technically if you pass away with no next of kin and nobody named in your will, then your pet will actually become property of the Queen! You can read more about that legal loophole in this interesting article on
Mirror.co.uk.
The good news is that is an extremely rare occurrence, and normally your pet will go to someone you actually know. If you and your pet already live with someone else and you have joint ownership of the pet, then they will normally stay together after your passing. When you don’t live with someone or have joint ownership, then the best thing to do is to name someone in your will who is going to take care of your pet; after all, your pet is classed as a personal belonging in the eyes of the law.