The production of $J/psi$ mesons with rapidity $1.5<y<4.0$ or $-5.0<y<-2.5$ and transverse momentum $p_mathrm{T}<14 mathrm{GeV}/c$ is studied with the LHCb detector in proton-lead collisions at a nucleon-nucleon centre-of-mass energy $sqrt{s_{NN}}=5 mathrm{TeV}$. The analysis is based on a data sample corresponding to an integrated luminosity of about $1.6 mathrm{nb}^{-1}$. For the first time the nuclear modification factor and forward-backward production ratio are determined separately for prompt $J/psi$ mesons and $J/psi$ from $b$-hadron decays. Clear suppression of prompt $J/psi$ production with respect to proton-proton collisions at large rapidity is observed, while the production of $J/psi$ from $b$-hadron decays is less suppressed. These results show good agreement with available theoretical predictions. The measurement shows that cold nuclear matter effects are important for interpretations of the related quark-gluon plasma signatures in heavy-ion collisions.