I have issue to remove ViewController from Navigation stack?

Hide default back button and add custom back button with action:

override func viewDidLoad {
    self.navigationItem.hidesBackButton = true
        let customBackButton = UIBarButtonItem(title: "Back", style: UIBarButtonItem.Style.plain, target: self, action: #selector(back))
        self.navigationItem.leftBarButtonItem = customBackButton

Use popToViewController to move back to specific viewcontroller:

@objc func back(sender: UIBarButtonItem) {
    guard let navigationController = self.navigationController else { return }
var navigationArray = navigationController.viewControllers // To get all 
self.navigationController!.popToViewController(navigationArray[navigationArray.count - 2], animated: true)