When does a caterpillar become a pupa?

I wouldn’t put too much thought into this. The whole of natural sciences is full of labels and borders. This is because of the way we humans think, we have the urge to have nature categorized nicely. In reality there are no labels, of course. So your butterfly is in the transitional stage between caterpillar and pupa, the molting is just one of the in-between-steps taken. Therefore I think both labels (caterpillar and pupa) would be correct at this stage.
But it isn’t really important imo.