Measurement of prompt and nonprompt charmonium suppression in PbPb collisions at 5.02 TeV