  We calculate the pion transition form factor ${\cal
F}_{\pi^0\gamma^*\gamma^*}(q_1^2,q_2^2)$, which describe the interaction of an
on-shell pion with two off-shell photons, using lattice QCD simulations with
two degenerate flavors of dynamical quarks. This form factor is the main
ingredient in the calculation of the pion-pole contribution to hadronic
light-by-light scattering in the muon $g-2$, $a_\mu^{\mathrm{HLbL}; \pi^0}$. We
focus our study on the spacelike region with photon virtualities up to
$1.5~\mathrm{GeV}^2$, not yet measured experimentally. Several lattice spacings
and pion masses are used to extrapolate the results to the physical point and a
comparison with different phenomenological models is performed. Finally, we use
our extrapolated form factor to provide a lattice determinaiton of
$a_\mu^{\mathrm{HLbL}; \pi^0}$.
