How can I set a value in core_config_data with Magento 2 programmatically?

This is how you should save data in magento2 core_config_data

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\Config\Storage\WriterInterface

/**
 *  @var \Magento\Framework\App\Config\Storage\WriterInterface
 */
protected $configWriter;

/**
 * @param WriterInterface $configWriter
 */
public function __construct(
    ....
    WriterInterface $configWriter
    .....
) {
    $this->configWriter = $configWriter;
}

add below line in your calling method:

$this->configWriter->save('my/path/whatever',  $value, $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeId = 0);

You can Inject ConfigInterface class and use it to save the value.

protected $_configInterface;

public function __construct(
    \Magento\Framework\App\Config\ConfigResource\ConfigInterface $configInterface
) {
    $this->_configInterface = $configInterface;
}

Then you can use it in your method like

$this->_configInterface
    ->saveConfig('section/group/field', $value, 'default', 0);