Standard MDM profile (no DEP) - you can try removing it via Settings → General → VPN & Device Management → profile → Remove. If the "Remove" button is missing, the organization has blocked removal. In that case, a factory reset helps (if there is no DEP).
DEP/ADE binding - can only be removed by the organization via Apple Business Manager. No reset, reflash, or DFU mode will help. On every activation, Apple servers check the serial number and restore the binding.
Supervised Mode - removed only by a full reset and reconfiguration via Apple Configurator. But if the device is also bound via DEP, Supervised will be restored automatically.
before buying a used device, always check MDM status via @ispyware_bot or GSX. If the seller offers to "remove MDM" for an extra fee, that is a red flag. Legitimate DEP removal is only possible by the owning organization.