There are a number of things that can cause the infection --
1. Urine pooling around the vulva or prepuce
2. Bladder stones
3. The bladder not being emptied long enough (urine sits there for a long time)
4. Kidney disease predisposes pets to UTIs
5. Immune compromise predisposes pets to UTIs
6. Puppies commonly gets UTIs from not cleaning themselves well, pooling urine, just being a normal puppy thing.
7. In males normal prepucial discharge can have bacteria in it that can travel up the urethra, especially if they have a lot of discharge.
For a dog to get a single UTI is not a major concern unless there are other changes on the urinalysis that make the vet worry about kidney problems, stones, etc.