The problem lies within the lines
//Case 4:Both Children
else
{
Node minRightNode = deleteNode.right;
while (minRightNode.left != null)
{
parent = minRightNode;
minRightNode = minRightNode.left;
}
...
}
You are setting the parent only if the minimum right node has a left child. In your scenario this is not true, hence parent
not set/ null. You can test this by changing the layout of the tree.