Option 1
When installing the factory (original) version of the ROM using Miflash, check clean all and lock
Option 2
Or you can install the ROM and use a script - clean all
If you are satisfied with the installed ROM, you can lock the bootloader with the command - fastboot oem lock
ATTENTION:
Redmi K40 / 40 Pro you can lock the bootloader only with Chinese ROM.
Poco F3 / Mi 11X you can lock the bootloader of any Global ROM.