### Is there an existing issue for this?

- [X] I have searched the existing issues

### Current behaviour

crash

### Expected behaviour

no crash

### Steps to reproduce

* Compile 79e8247ddb166f9b980f40249b7372a502402a4d
* Type `migratewallet`

### Relevant log output

```
wallet/scriptpubkeyman.cpp:1915: std::optional<MigrationData> wallet::LegacyScriptPubKeyMan::MigrateToDescriptor(): Assertion `IsMine(desc_spk) != ISMINE_NO' failed.
Aborted (core dumped)
```


### How did you obtain Bitcoin Core

Compiled from source

### What version of Bitcoin Core are you using?

current master

### Operating system and version

Linux

### Machine specifications

_No response_
{
    LOCK(cs_wal);
    auto mi = mapWal.find(originalHash);
    // T
    assert(mi != mapWal.end());
    CWalTx& wtx = (*mi).second;
    // E
    assert(wtx.mapValue.count("replaced_by_txid") == 0);
    wtx.mapValue["replaced_by_txid"] = newHash.ToString();
    // R
    RefreshMempoolStatus(wtx, chain());
    WalBatch batch(GetDatabase());
    bool success = true;
    if (!batch.WriteTx(wtx)) {
        WalLogPrintf("%s Updating batch tx %s failed\n", __func__, wtx.GetHash().ToString());
        success = false;
    }
    NotifyTransactionChanged(originalHash, CT_UPDATED);
    return success;
}
void CWalSetSKeyState(WalBatch& batch, const uint256& hash, unsigned int n, bool used, stdset<CTxDestination>& tx_destinations)
{
    AssertLockHeld(cs_wal);
    const CWalTx* srctx = GetWalTx(hash);
    if (!srctx) return;
    CTxDestination dst;
    if (ExtractDestination(srctx->tx->vout[n].scriptPubKey, dst)) {
        if (IsMine(dst)) {
            if (used != IsAddressPreviouslyS(dst)) {
                if (used) {