It is thought that the behavior you are describing, known as “the Zoomies,” is the result of a release of pent-up energy or excitement.

Some dogs may exhibit this behavior before going to the bathroom as a way of releasing energy and getting in the right mindset to eliminate.

It is also possible that your dog is simply excited to go outside to eliminate and the Zoomies are a manifestation of that excitement.