The formula for CMD includes modifiers for Strength, Dexterity, and Size, which means the net difference may be zero.
A creature's Combat Maneuver Defense (CMD) is normally calculated as follows:
CMD = 10 + Base attack bonus + Strength modifier + Dexterity modifier + special size modifier + miscellaneous modifiers
When your character polymorphs or otherwise changes size, some of these modifiers may increase or decrease, depending on what method your character used to transform. This means the character's attack bonuses, CMB, AC, CMD, and some other stats would be recalculated.
A creature's size modifier is determined by their current size category. For example, a Medium creature's size modifier is +0, and a Tiny creature's size modifier is +2. This modifier is always added to attack rolls and AC, added 2x to Fly checks and 4x to Stealth checks, but it is subtracted from CMB and CMD.
In your example, your math is correct. Suppose a Medium-sized humanoid uses Beast Shape II to become a Tiny animal. This changes their size modifier from +0 to +2. They also get a "+4 size bonus" to their Dexterity score, which translates to a +2 increase to their Dexterity modifier.
(The bonus to natural armor is not added to CMD.)
When recalculating CMD this way, you add their new Dexterity modifier (which is +2 higher than before), and subtract the new size modifier (which is +2). Compared to their previous CMD (when they were Medium-sized), the net difference is +2 - (+2) = 0.