I wrote a wee module based on your code above and it worked ok. Here's my code for comparison. (I set URL params like ?newusr=fredc&newpwd=fredc)
$app = Factory::getApplication(); // equivalent of $app = JFactory::getApplication();
$input = $app->input;
if ($input->exists('newusr') && $input->exists('newpwd'))...
The answer by @saibbyweb resulted in an infinite redirect loop in Joomla 3.9.
I then figured out that my problem was with the component I was trying to access, com_akeebasubs, which used:
$this->container->platform->redirect(\JUri::base() .'index.php?option=com_users&view=login&return=' . $myURI);
The redirect worked properly after I ...
The documentations has this : https://api.joomla.org/cms-3/classes/Joomla.CMS.User.User.html but it seems that no parameters are passed to user->delete?
That's correct. This method works on the user instance.
// Get user with ID 1.
$userId = 1;
$user = User::getInstance($userId);
// Delete the user.