That it is not determined by the rules, but rather at GM's discretion.
There seem to be some controversy on this matter!
Mike Mearls: NO
On the somewhat related question shown up by Sdjz (Posession isn't exactly a spell), tim-grant quotes Mike Mearls:
Does Charm Person ends if polymorph is cast on the charmed humanoid, changing its type to beast?
Mike Mearls: nope, restriction applies to targeting - sticks after successful cast #wotcstaff
Since Charm Person requires a Humanoid target, the possession should not end by a successful Polymorph, according to Mike Mearls.
Note that Mearls' Tweets are not considered official but just how he would rule them at his table. Read them as advice from an experienced GM, but remember they are not "official" in the way that Jeremy Crawford's (cited below) are.
Jeremy Crawford: Yes
However the accepted answer on that thread specifies that changing shape into a non-humanoid form, will end form-dependent spells.
As specified by BlueMoon93, Jeremy Crawford specifies in a Sage Advice:
In #DnD, the exceptional trumps the general. (No longer being a valid target trumps condition carryover.)
As @Adam says in a related answer:
Dominate Person requires a humanoid target. All official PC races are humanoid, so while the druid is in its normal form it can be targeted and charmed by a Dominate Person spell. If the druid wildshapes into a beast, its type changes to match that beast. So, the druid is no longer a humanoid, the target of Dominate Person is invalid, and the spell ends. In this way, it works in reverse of the Dominate Beast spell.
Dominate Monster works on any creature. Whether in beast form, humanoid form, or even in a Circle of the Moon druid's elemental form, the druid is still a creature. Thus, even going in and out of wild shape won't make the druid an invalid target. Since the target is still valid, the Dominate Monster spell will still have full effect, even if the druid wild shapes.