The PHENIX experiment at the Relativistic Heavy Ion Collider has measured the differential cross section, mean transverse momentum, mean transverse momentum squared of inclusive $J/psi$ and cross-section ratio of $psi(2S)$ to $J/psi$ at forward rapidity in pp collisions at sqrts = 510 GeV via the dimuon decay channel. Comparison is made to inclusive $J/psi$ cross sections measured at sqrts = 200 GeV and 2.76--13 TeV. The result is also compared to leading-order nonrelativistic QCD calculations coupled to a color-glass-condensate description of the low-$x$ gluons in the proton at low transverse momentum ($p_T$) and to next-to-leading order nonrelativistic QCD calculations for the rest of the $p_T$ range. These calculations overestimate the data at low $p_T$. While consistent with the data within uncertainties above $approx3$ GeV/$c$, the calculations are systematically below the data. The total cross section times the branching ratio is BR $dsigma^{J/psi}_{pp}/dy (1.2<|y|<2.2, 0<p_T<10~mbox{GeV/$c$}) =$ 54.3 $pm$ 0.5 (stat) $pm$ 5.5 (syst) nb.