It seems like issuing listsinceblock rpc calls while bitcoind is processing blocks can result in lastblock and confirmations values that disagree with each-other -- the number of confirmations is not relative to the lastblock.
I'm able to reliably reproduce this by issuing listsinceblock calls from a blocknotify handler. Here's a reproduction script:
#!/bin/bash
shopt -s expand_aliases
trap 'bcli stop' SIGINT SIGTERM EXIT
DIR=/tmp/test-bitcoin
rm -rf $DIR && mkdir $DIR
bopt="-regtest -datadir=$DIR -rpcport=8763"
alias bcli="bitcoin-cli $bopt"
alias miner="bcli -rpcwallet=miner"
alias wallet="bcli -rpcwallet=wallet"
# Mine some coins without triggering `blocknotify`
bitcoind $bopt -nolisten -daemon -wallet=miner
miner generatetoaddress 101 `miner -rpcwait getnewaddress` > /dev/null
bcli stop && sleep 1
# Now start with `blocknotify` and create a separate wallet to avoid cluttering `listsinceblock` with mining-related txs
bitcoind $bopt -nolisten -daemon -wallet=miner -fallbackfee=0.00001 \
-blocknotify="bitcoin-cli $bopt -rpcwallet=wallet listsinceblock | tee -a $DIR/notify.log"
bcli -rpcwait createwallet wallet
miner sendtoaddress `wallet getnewaddress` 1
miner generatetoaddress 20 `miner getnewaddress`
cat $DIR/notify.log | jq -c '{lastblock: .lastblock, tx: (.transactions[] | [.txid,.confirmations,.blockheight])}'
This is the output of the jq command on the last line of the script, with Bitcoin Core 0.20.0:
{"lastblock":"3d37a7b824a9250a87e78be88c1c58dcad737d4c43ddb1a1c6dea46e9a56b5ff","tx":["58cf095ffcd93ab838b6382435f1c9b7b8ea4daac8128c93a8b2d67b60715d16",4,102]}
{"lastblock":"7092dd077f8e6306ac649e7ebbb24d2b7840702b8a509a225912d7192bf8f3ae","tx":["58cf095ffcd93ab838b6382435f1c9b7b8ea4daac8128c93a8b2d67b60715d16",8,102]}
{"lastblock":"7092dd077f8e6306ac649e7ebbb24d2b7840702b8a509a225912d7192bf8f3ae","tx":["58cf095ffcd93ab838b6382435f1c9b7b8ea4daac8128c93a8b2d67b60715d16",8,102]}
{"lastblock":"2f1370f3efd68cad09131a3aa4d763c79e37c7253175db2e136089bfd24387ea","tx":["58cf095ffcd93ab838b6382435f1c9b7b8ea4daac8128c93a8b2d67b60715d16",9,102]}
{"lastblock":"2f1370f3efd68cad09131a3aa4d763c79e37c7253175db2e136089bfd24387ea","tx":["58cf095ffcd93ab838b6382435f1c9b7b8ea4daac8128c93a8b2d67b60715d16",12,102]}
{"lastblock":"2f1370f3efd68cad09131a3aa4d763c79e37c7253175db2e136089bfd24387ea","tx":["58cf095ffcd93ab838b6382435f1c9b7b8ea4daac8128c93a8b2d67b60715d16",12,102]}
{"lastblock":"4c2ccc8d0efda2d73a00a661f8fd7820bf60c59d8022894e63efb1d4f170c578","tx":["58cf095ffcd93ab838b6382435f1c9b7b8ea4daac8128c93a8b2d67b60715d16",13,102]}
{"lastblock":"4c2ccc8d0efda2d73a00a661f8fd7820bf60c59d8022894e63efb1d4f170c578","tx":["58cf095ffcd93ab838b6382435f1c9b7b8ea4daac8128c93a8b2d67b60715d16",14,102]}
{"lastblock":"4c2ccc8d0efda2d73a00a661f8fd7820bf60c59d8022894e63efb1d4f170c578","tx":["58cf095ffcd93ab838b6382435f1c9b7b8ea4daac8128c93a8b2d67b60715d16",15,102]}
{"lastblock":"4c2ccc8d0efda2d73a00a661f8fd7820bf60c59d8022894e63efb1d4f170c578","tx":["58cf095ffcd93ab838b6382435f1c9b7b8ea4daac8128c93a8b2d67b60715d16",15,102]}
{"lastblock":"4c2ccc8d0efda2d73a00a661f8fd7820bf60c59d8022894e63efb1d4f170c578","tx":["58cf095ffcd93ab838b6382435f1c9b7b8ea4daac8128c93a8b2d67b60715d16",15,102]}
{"lastblock":"4c2ccc8d0efda2d73a00a661f8fd7820bf60c59d8022894e63efb1d4f170c578","tx":["58cf095ffcd93ab838b6382435f1c9b7b8ea4daac8128c93a8b2d67b60715d16",15,102]}
{"lastblock":"635449428c88781cc80747a77b9c59d9f46263e6f606c8306b021116d32a8320","tx":["58cf095ffcd93ab838b6382435f1c9b7b8ea4daac8128c93a8b2d67b60715d16",16,102]}
{"lastblock":"412240b03e197502b228b95396d3d8386499ed5acf2a0ac30d08b34e798b7bf0","tx":["58cf095ffcd93ab838b6382435f1c9b7b8ea4daac8128c93a8b2d67b60715d16",18,102]}
{"lastblock":"54ea16118338039c672229f3834db8917cfc5b25b870c7db7d800587ea117895","tx":["58cf095ffcd93ab838b6382435f1c9b7b8ea4daac8128c93a8b2d67b60715d16",19,102]}
{"lastblock":"54ea16118338039c672229f3834db8917cfc5b25b870c7db7d800587ea117895","tx":["58cf095ffcd93ab838b6382435f1c9b7b8ea4daac8128c93a8b2d67b60715d16",19,102]}
{"lastblock":"181e7bbcee44402a67f171404611a3885238338555ab58039b1330249662f87f","tx":["58cf095ffcd93ab838b6382435f1c9b7b8ea4daac8128c93a8b2d67b60715d16",20,102]}
Notice how lastblock is reported as 4c2ccc8d.. with 13 confirmations for tx 58cf095f..., then later with 14 confirmations for the same block and tx, then later with 15.
You may need to generate more than 20 blocks if you're not able to catch this. For the tests I ran, it seems like 20 (or even 10) was sufficient.