A dog walks around before using the bathroom because it's a natural instinct and has something to do with hygiene.
I think it is because they're making sure the spot they're gonna be pooping is clean and hasn't been pooped on before.
Another reason dogs walk in circles is due to the earths magnetic field. Some dogs will also walk in circles or spin around before lying down to go to sleep.