Three-body forces acting on a Λ hyperon in a nuclear medium are investigated, with special focus on the so-called hyperon puzzle in neutron stars. The hyperon-nucleon two-body interaction deduced from SU(3) chiral effective field theory is employed at next-to-leading order. Hyperon-nucleon three-body forces are approximated using saturation by decuplet baryons and are transcribed to density-dependent effective two-body interactions. These together are taken as input in a Brueckner-Bethe-Goldstone equation with explicit treatment of the ΛN↔ΣN and ΛNN↔ΣNN coupled channels. Single-particle potentials of a Λ hyperon in symmetric nuclear matter and neutron matter are calculated. With parameters of the ΛNN three-body force constrained by hypernuclear phenomenology, extrapolations to high baryon density are performed. By comparison of the Λ and neutron chemical potentials at densities characteristic of the core of neutron stars it is found that the combined repulsive effects of two- and three-body correlations makes the appearance of Λ hyperons in neutron stars energetically unfavourable, thus offering a possible solution to a longstanding question.