You're changing the behavior of some code. You see a tidying that would make it easier to change. You tidy. Then you write another test case. Now you need to change the behavior some more. That leads to more tidying. An hour later you:
Actually understand all the behavior changes that need to be made.
Actually understand all the tidying that eases those behavior changes.
But you have a mess of tidyings & changes all tangled together.
You have at least 3 options, none of them attractive:
Ship it as is. This is impolite to reviewers & prone to errors but it's quick.
Untangle the tidyings and changes into separate PRs, or a sequence of PRs, or a sequence of commits in a single PR. This is more polite but it can be a lot of work.
Discard your work in progress & start over, tidying first. This is more work but it leaves a coherent chain of commits.