When you capture a wild Pokemon with its hidden ability (HA), it appears that it re-rolls the chance for HA upon evolution. This issue does not seem to exist for Pokemon that got their HA through /pokeedit, /pokespawn, /pokegive, the PokeEditor tool, breeding (passed down from a parent), or an ability patch.
The most effective and efficient way to replicate the bug is to change the "hidden-ability-rate" setting in the "general.yml" config file to a low value. I used a value of 5 but 2 probably would work best. Using a value of 1, guaranteeing an HA for capture, does not work for replicating the bug as on evolution it will always retain its HA since there is a 100% chance to "re-roll" it again. Just spam-capture a few Pokemon until you find an HA. Then evolve the HA Pokemon. From other cases, it seems like the evolution method does not matter but in my testing, I just leveled up Magikarps with rare candy. When you evolve the Pokemon, it seems like there is an equal chance of retaining the HA as there was for getting one in the first place (20% chance for the value of 5 I was using in the config setting). With a default, or otherwise high, "hidden-ability-rate" setting, the HA is lost virtually every time you evolve a naturally captured HA Pokemon