That behavior is controlled by two options:
Group outputs by address, selecting all or none, instead of selecting on
a per-output basis. Privacy is improved as an address is only
used once (unless someone sends to it after spending from it),
but may result in slightly higher fees as suboptimal coin
selection may result due to the added limitation (default: 0
(always enabled for wallets with "avoid_reuse" enabled))
-maxapsfee=
Spend up to this amount in additional (absolute) fees (in BTC) if it
allows the use of partial spend avoidance (default: 0.00)
The first, if enabled, forces all payments to the same address to always be grouped.
Otherwise, it tries computing the transaction both ways, and if the grouped way doesn't pay more than a threshold amount of fees more then it uses the grouped way. The default threshold is the conservative value of 0. ... so it will prefer to group the inputs, but only if doing so doesn't make it pay more in total fees.
This is still kinda dumb: the threshold should probably be in terms of fee ABOVE the minimum feerate (e.g. so if your transaction is at the minimum feerate, it'll always do it, because you were going to pay the minimum feerate eventually in any case)... but at least it's something.