Well, it could be that the dog was a gift from a dear friend of the Potters. Or perhaps they came across it while on a magical adventure and formed an instant bond.
Sometimes in fanfiction, the Potters might have rescued the dog from a dangerous situation. This act of heroism led to the dog becoming a loyal companion. Another possibility is that the dog simply showed up at their doorstep one day and they couldn't resist keeping it.
In some fanfics, the Potters might have adopted the dog from a shelter. Maybe they found it abandoned and decided to give it a loving home.