Through the campaign, gem levels go up in a deterministic fashion.
In acts 1 and 2, about once per 4 zone levels, new tiers of gems become available.
Acts 3 to 5 it is a little slower, but you will still get upgrades every 5 or so zone levels.
From level 62 onward (act 6), RNG becomes a factor in gem drops. There's a most common gem level to drop, but one other gem level (62-65) or two other gem levels (zone level 66+) are also possible.
This is why level 20 gems are so rare.
They can only drop on the level 82 and higher loot tables, so zone level 81 or above, and even then there is a strong bias toward getting level 18 gems and a weak one toward getting level 19.
This bias has been datamined. See loot tables, below.
Lost Techniques may also be able to drop high level gems, but it has not procced for me yet.