I’m not sure how, but she’s become aware of the concept of being “in trouble” and she’s not a fan of it. It’s funny to me that she understands what being in trouble is, because we’ve never actually said, “You’re in trouble now, go to your room,” or the like. She may not know what “trouble” is, but she knows it’s not good and she doesn’t want to be in it. By the way, when we’re in a restaurant or somewhere else in public, the question changes to, “Do you need to go outside?” (I refuse to allow a tantrum in a restaurant or other public place and instead take her outside to calm her down. She doesn’t come back in until the tantrum subsides. I would rather eat an entire meal re-heated at home versus fresh at a restaurant if it means I maintain control and she isn’t allowed to pitch a fit in a restaurant.)
So, the concept of being “in trouble” is one your 2-year-old may be aware of and probably doesn’t like. If not, you should avail yourself the next opportunity to make her aware. Clearly tell her she’s in trouble and she needs to stay in her room (or whatever her particular punishment may be) until she’s no longer in trouble and explain that she will no longer be in trouble when she stops her tantrum. This will arm you later to be able to ask the simple question and have a chance of stopping a tantrum on the up tick, instead of handling it once it’s already at full steam.