Automatic CAN bus termination
The first thing you must do is to fix your incorrect connector pin-out and turn it into CAN. DB9 connectors for CAN are widely standardized and professional engineers follow industry standards. You should have CANHI=7, CANLO=2, GND=3.
Once you have turned your pin-out into CAN, the simplest solution might be to buy pre-made DB9 terminators and plug those in whenever you don't connect the buses together. For example these: https://www.kvaser.com/product/kvaser-d-sub-9-pin-120-ohm-termination-adapter-2/ (though Kvaser specifically are ridiculously expensive - there's plenty of 2nd source doing the same thing for a 10th of the price).
Alternatively, you could also connect two pins of the DB9 connector together at each end (to once again violate the standard pin-out...) and then have that signal activate an analog switch, which in turn enables the resistor on that board only. Larger BOM but cheaper external adapters.