I've noticed that Free Chests and Crown Chests may give Gems to the player. I've also noticed that this number may vary, and the Free Chests may often not give any Gems at all. How are Gem loots calculated?
The number of gems is randomized, even the gems card itself has a chance to appear (or not to). But according to the Clash Royale Wiki section for gems:
Free chests and Crown chests are the only chests to contain gems, containing 2-4 gems.
Free chests have a chance of giving you gems but Crown Chests will always give you gems:
Free Chests don't always contain Gems, but Crown Chests always do.