There being no orders to the contrary, a commander can exercise his own judgement and surrender if the circumstances dictate. But sometimes his superior orders him to continue to fight regardless of the cost, or simply doesn't leave room for discretion. Lee found himself in that situation with Davis.
That is why Lee's orders to his subordinates always included the words "if practical", to make them discretionary. Davis didn't have enough sense to recognize reality when it hit him in the face, and even ordered Johnston to continue to fight after the ANV had surrendered, an order which Johnston ignored (the exception to this thesis). Jackson once court-martialed an officer who withdrew his men from an exposed position where the unit was out of ammunition, on the grounds that Jackson hadn't issued an order authorizing the withdrawal.