Posterior predictive checking for gravitational-wave detection with pulsar timing arrays. I. The optimal statistic