Let's say that a medium-sized Druid wild shapes into something like a fly (fine sized) and flies into a medium-sized NPC's mouth while they were talking, gets swallowed, and then wild-shapes back into their humanoid form. What would happen in this instance? Would the Druid take damage? Would the NPC take damage?
The Monster Manual and DMG have 2 possible solutions to this:
you could treat it like the same mechanics that the Tarrasque (MM p.286-7) uses to swallow, but scaled down to whoever swallowed the druid, or
use the "inside an object" (as in the Daern's Instant Fortress) mechanic from the DMG, where both would take force damage based on their size: most likely 1d10 if they were both medium humanoids.
As a DM, I would rule that it would kill both of them. The NPC would hemorrhage to death; the druid would be suffocated. There's no provision in the rules for stopping such a transformation in mid-change; it all happens in seconds. And the druid would automatically revert to human form upon falling unconscious, which would happen quickly to a fly immersed in stomach acid.
Elemental Wild Shape would be another story -- a fire elemental would burn its way out, an air elemental could simply be exhaled, an earth elemental would shatter the ribcage and pelvis, and a water elemental would turn the unhappy target into a high-pressure fountain -- but I don't see anything in the rules that allows transformation from beast shape to beast shape, from beast shape to elemental shape or from elemental shape to beast shape. So the druid couldn't turn into a fly, be swallowed, then turn directly into an elemental.
Here's the genuinely nasty trick: Thousand Forms, which allows the casting of alter self at will. Turn into a fly, zip down the esophagus, then use the Natural Weapons option and sprout sea urchin spines. *shudder*
I would assume he'd just stop growing until he came back out. In Pathfinder, when you're growing after being affected by an "enlarge person" spell, if you reach the limits of your confines, you stop growing.