  The production of $\eta$ and $\eta'$ mesons is studied in proton-proton and
proton-lead collisions collected with the LHCb detector. Proton-proton
collisions are studied at center-of-mass energies of $5.02$ and $13~{\rm TeV}$,
and proton-lead collisions are studied at a center-of-mass energy per nucleon
of $8.16~{\rm TeV}$. The studies are performed in center-of-mass rapidity
regions $2.5<y_{\rm c.m.}<3.5$ (forward rapidity) and $-4.0<y_{\rm c.m.}<-3.0$
(backward rapidity) defined relative to the proton beam direction. The $\eta$
and $\eta'$ production cross sections are measured differentially as a function
of transverse momentum for $1.5<p_{\rm T}<10~{\rm GeV}$ and $3<p_{\rm
T}<10~{\rm GeV}$, respectively. The differential cross sections are used to
calculate nuclear modification factors. The nuclear modification factors for
$\eta$ and $\eta'$ mesons agree at both forward and backward rapidity, showing
no significant evidence of mass dependence. The differential cross sections of
$\eta$ mesons are also used to calculate $\eta/\pi^0$ cross section ratios,
which show evidence of a deviation from the world average. These studies offer
new constraints on mass-dependent nuclear effects in heavy-ion collisions, as
well as $\eta$ and $\eta'$ meson fragmentation.
