>>55989491it actually happen in Gen 3-5. In those Gens, the personality value created whenever a Pokemon is generated is linked to that pokemon's gender. Depending on gender ratio of a pokemon species there is a threshold, greater or equal to that threshold results in male, less results in female.
an individual pokemon keeps its personality value for as long as it exists. So if an female Azumaril evolves, its personality value has a chance of passing the Marill threshold since Marill's threshold is lower, resulting in a male.
This no longer happens in Gen 6 because the way gender is calculated changed.