An iCloud lock associates the serial number of an iPhone to an iCloud account.
No matter which way you erase the device, as soon as the device connects to the internet (this cannot be skipped, either through cellular, wifi, or wired to a computer), the first thing that happens is the device connects to the Apple servers and sends the serial number and checks if it's locked or not.
There are videos showing iCloud lock removals by reprogramming the chips that have the serial to a different number, but that involves completely disassembling the device and desoldering a specific chip from the logic board, then reprogramming it with a very specific piece of hardware. I'm not sure if that still works, the last video I saw of it was an iPhone 6S from years ago.