Those wallet have some mechanism to identify which derivation path to get to that extended key and the script type to use,
In Bitcoin Core and Sparrow, they use "descriptors".
In Sparrow, it can be seen in "Edit wallet output descriptor" button:
From that, your example wallet uses "wpkh" (P2WPKH) script type and the derivation path of m/84h/0h/0h from master private key to that extended public key.
Wallets supporting descriptors utilizes that.
For the recovery of that particular case when the user simply imported the xpub resulting with legacy HD watch-only wallet, you don't need a third-party tool nor command to recover it;
When importing to Electrum during script type selection screen:
Tick "legacy (p2pkh)", then edit the derivation path below from m/44h/0h/0h to m/84h/0h/0h to match the derivation path in your descriptor.
Then finalize the wallet creation process and the xpub and the legacy addresses of the improperly imported watch-only wallet should match.