This writes 32 and a hash. This is very likely because it is meant to write a 32 byte string. This is not the format of the merge mining tag. From Monero's tx_extra.h:
Depth is a varint, which is usually 0. crypto::hash is not a string, but a fixed length field, so its length is not written in the bitstream.
It happens to be a valid merge mining tag with depth 32, but by chance.
Additionally, in block_template.cpp again:
// Calculate sidechain id with this extra_nonce
const hash sidechain_id = calc_sidechain_hash(extra_nonce);
const size_t sidechain_hash_offset = extra_nonce_offset + m_poolBlockTemplate->m_extraNonceSize + 2;
This code assumes the depth varint is one byte (which is the case for both 32 and 0 in practice).
In block_template.cpp:
This writes 32 and a hash. This is very likely because it is meant to write a 32 byte string. This is not the format of the merge mining tag. From Monero's tx_extra.h:
Depth is a varint, which is usually 0. crypto::hash is not a string, but a fixed length field, so its length is not written in the bitstream. It happens to be a valid merge mining tag with depth 32, but by chance.
Additionally, in block_template.cpp again:
This code assumes the depth varint is one byte (which is the case for both 32 and 0 in practice).