  Searches are performed for a low-mass dimuon resonance, $X$, produced in
proton-proton collisions at a center-of-mass energy of 13 TeV, using a data
sample corresponding to an integrated luminosity of 5.1 fb$^{-1}$ and collected
with the LHCb detector. The $X$ bosons can either decay promptly or displaced
from the proton-proton collision, where in both cases the requirements placed
on the event and the assumptions made about the production mechanisms are kept
as minimal as possible. The searches for promptly decaying $X$ bosons explore
the mass range from near the dimuon threshold up to 60 GeV, with nonnegligible
$X$ widths considered above 20 GeV. The searches for displaced $X \to
\mu^+\mu^-$ decays consider masses up to 3 GeV. None of the searches finds
evidence for a signal and 90% confidence-level exclusion limits are placed on
the $X \to \mu^+\mu^-$ cross sections, each with minimal model dependence. In
addition, these results are used to place world-leading constraints on
GeV-scale bosons in the two-Higgs-doublet and hidden-valley scenarios.
