  A study of strange hadron production associated with hard scattering
processes and with the underlying event is conducted to investigate the origin
of the enhanced production of strange hadrons in small collision systems
characterised by large charged-particle multiplicities. For this purpose, the
production of the single-strange meson ${\rm K^0_S}$ and the double-strange
baryon $\Xi^{\pm}$ is measured, in each event, in the azimuthal direction of
the highest-$p_{\rm T}$ particle (``trigger" particle), related to hard
scattering processes, and in the direction transverse to it in azimuth,
associated with the underlying event, in pp collisions at $\sqrt{s}=5.02$ TeV
and $\sqrt{s}=13$ TeV using the ALICE detector at the LHC. The per-trigger
yields of ${\rm K^0_S}$ and $\Xi^{\pm}$ are dominated by the
transverse-to-leading production (i.e., in the direction transverse to the
trigger particle), whose contribution relative to the toward-leading production
is observed to increase with the event charged-particle multiplicity. The
transverse-to-leading and the toward-leading $\Xi^{\pm}$/${\rm K^0_S}$ yield
ratios increase with the multiplicity of charged particles, suggesting that
strangeness enhancement with multiplicity is associated with both hard
scattering processes and the underlying event. The relative production of
$\Xi^{\pm}$ with respect to ${\rm K^0_S}$ is higher in transverse-to-leading
processes over the whole multiplicity interval covered by the measurement. The
${\rm K}^{0}_{\rm{S}}$ and $\Xi^{\pm}$ per-trigger yields and yield ratios are
compared with predictions of three different phenomenological models, namely
PYTHIA 8.2 with the Monash tune, PYTHIA 8.2 with ropes and EPOS LHC. The
comparison shows that none of them can quantitatively describe either the
transverse-to-leading or the toward-leading yields of ${\rm K}^{0}_{\rm{S}}$
and $\Xi^{\pm}$.
