Nuclear modification factor of D$^0$ mesons in PbPb collisions at $\sqrt{s_\mathrm{NN}} =$ 5.02 TeV