Arizona's gas prices sit above the national average for several reasons. The state requires a special reformulated fuel blend in the Phoenix metro area to meet EPA air quality standards — this "Arizona blend" costs more to produce and can only be sourced from a limited number of refineries, mainly in California.
Arizona has no in-state refineries, so all fuel is imported — primarily from California refineries via the Kinder Morgan pipeline. Any refinery outage or pipeline disruption hits Arizona prices immediately. Flagstaff and northern Arizona pay a premium on top of that due to their distance from the pipeline terminal in Phoenix.
Yuma and western border cities sometimes see lower prices due to proximity to cheaper California desert stations and competition from across the California border.
Sources: AAA State Gas Price Averages · EIA Gasoline & Diesel Update · ADEQ Arizona Fuel Requirements