The fractions of non-prompt (i.e. originating from beauty-hadron decays) D0 and D+ mesons with respect to the inclusive yield are measured as a function of the charged-particle multiplicity in proton-proton collisions at a centre-of-mass energy of s = 13 TeV with the ALICE detector at the LHC. The results are reported in intervals of transverse momentum (p T) and integrated in the range 1 < p T < 24 GeV/c. The fraction of non-prompt D0 and D+ mesons is found to increase slightly as a function of p T in all the measured multiplicity intervals, while no significant dependence on the charged-particle multiplicity is observed. In order to investigate the production and hadronisation mechanisms of charm and beauty quarks, the results are compared to PYTHIA 8 as well as EPOS 3 and EPOS 4 Monte Carlo simulations, and to calculations based on the colour glass condensate including three-pomeron fusion. [Figure not available: see fulltext.].