It doesn't appear that gems are a naturally evolved lifeform. Gems are essentially sapient crystalline supercomputers projecting a hard light holographic form around themselves for instrumentality. Some other species invented gems and used them for some purpose before losing control over them.
The creation of gems is an industrial process. A planet with the proper resources has to be identified. Injectors have to be transported there and set up in kindergartens. Gems might have been created to terraform other planets for the benefit of their creators. Those creators could have died off leaving gems behind who continued expanding across the universe. The gems could have rebelled against their creators. Essentially gems are like Fred Saberhagen's Berserkers or Star Trek's Nomad or V'Ger. They're an out of control creation following their last instruction.