It's easier to do in tesnet because you can easily set a configuration to accept non-standard transactions to your mempool.
While in mainnet, the config wont work.
Actually it was not possible in TestNet either. I've tried it and the transaction was rejected, hence mining the block myself.
IDK if there're other ways aside from changing the code but if there is
The problem is this flag: SCRIPT_VERIFY_WITNESS_PUBKEYTYPE
The way I understand bitcoin core's code is that it doesn't disable or change flags on different networks, it just skips the IsStandard check in
validation.cpp on TestNet while the non-standard flag is still used for verification of scripts eg. in
interpretter.cpp and rejects this non-standard script. This flag however is not present while verifying a block since it is not a consensus rule.
If I'm correct, removing
this single line should fix it for accepting the transactions in mempool, or just not use standard flags in any other way that core allows it.