How do $\pi^0$ particles exist?

Actually, the quark and antiquark do annihilate with each other. It just takes some amount of time for them to do so. The actual time that it takes for any given pion is random, and follows an exponential distribution, but the average time it takes is $8.4\times 10^{-17}\,\mathrm{s}$ according to Wikipedia, which we call the lifetime of the neutral pion.

What you've learned is a simplification, in fact (it pretty much always is in physics). The actual state of a pion is a linear combination of the up state and the down state,

$$\frac{1}{\sqrt{2}}(u\bar{u} - d\bar{d})$$

This is how it's able to be its own antiparticle: there aren't separate up and down versions of the neutral pion. Each one is a combination of both flavors.

The orthogonal linear combination,

$$\frac{1}{\sqrt{2}}(u\bar{u} + d\bar{d})$$

doesn't correspond to a real particle. (In a sense it "contributes" to the $\eta$ and $\eta'$ mesons, but I won't go into detail on that.)