How to delete a product in Magento-2 programmatically?

If you try to delete product from fronend then you need to assign area for that.

Add following code to your class.

public function __construct(
    ........
    \Magento\Catalog\Model\ProductRepository $productRepository,
    \Magento\Framework\Registry $registry
) {
    ......
    $this->productRepository = $productRepository;
    $this->registry = $registry;
}

Following code is for deleting product.

$this->registry->register('isSecureArea', true);
// using sku
$this->productRepository->deleteById('Z62676');

// using product id
$product = $this->productRepository->getById(1);
$this->productRepository->delete($product);

First, I suggest you try to avoid using the ObjectManager directly

Second, I reckon you should use the \Magento\Catalog\Api\ProductRepositoryInterface service contrat to delete a product:

protected $_productRepositoryInterface;

public function __construct(
     ...
     \Magento\Catalog\Api\ProductRepositoryInterface $productRepositoryInterface, 
     ...
) {
    ...
    $this->_productRepositoryInterface = $productRepositoryInterface;
    ...
}

Then in your code you can do:

$product = $this->_productRepositoryInterface->getById($productID);
$this->_productRepositoryInterface->delete($product);

Note that if you have the sku of your product you can do it in one line:

$this->_productRepositoryInterface->deleteById($productSku);

Indeed, you cannot delete product on the frontend area.

You need to force the SecureArea registry.

But if you check the register function, you see that you cannot override an existent key value. You need to unregister the key before register it.

/**
 * Register a new variable
 *
 * @param string $key
 * @param mixed $value
 * @param bool $graceful
 * @return void
 * @throws \RuntimeException
 */
public function register($key, $value, $graceful = false)
{
    if (isset($this->_registry[$key])) {
        if ($graceful) {
            return;
        }
        throw new \RuntimeException('Registry key "' . $key . '" already exists');
    }
    $this->_registry[$key] = $value;
}

Solution based on other posts :

Constructor :

public function __construct(
    ........
    \Magento\Catalog\Model\ProductRepository $productRepository,
    \Magento\Framework\Registry $registry
) {
    ......
    $this->productRepository = $productRepository;
    $this->registry = $registry;
}

Logic :

$this->registry->unregister('isSecureArea');
$this->registry->register('isSecureArea', true);
// using sku
$this->productRepository->deleteById('Z62676');

// using product id
$product = $this->productRepository->getById(1);
$this->productRepository->delete($product);