The relative modification of the prompt ψ(2S) and J/ψ yields from pp to PbPb collisions, at the center-of-mass energy of 5.02 TeV per nucleon pair, is presented. The analysis is based on pp and PbPb data samples collected by the CMS experiment at the LHC in 2015, corresponding to integrated luminosities of 28.0 pb-1 and 464 μb-1, respectively. The double ratio of measured yields of prompt charmonia reconstructed through their decays into muon pairs, (Nψ(2S)/NJ/ψ)PbPb/(Nψ(2S)/NJ/ψ)pp, is determined as a function of PbPb collision centrality and charmonium transverse momentum pT, in two kinematic intervals: |y|<1.6 covering 6.5<pT<30 GeV/c and 1.6<|y|<2.4 covering 3<pT<30 GeV/c. The centrality-integrated double ratios are 0.36±0.08(stat)±0.05(syst) in the first interval and 0.24±0.22(stat)±0.09(syst) in the second. The double ratio is lower than unity in all the measured bins, suggesting that the ψ(2S) yield is more suppressed than the J/ψ yield in the explored phase space.