Scriptures do not describe how they do it, but they do describe that wearing certain gems give benefits like destruction of sin, protection from snakes, etc. For example, consider the following verse of the Garduda Purana:
teṣu rakṣoviṣavyālavyādhighnānyaghahāni ca
prādurbhavanti ratnāni tathaiva viguṇāni ca [GP - 1.68.8]
Among the gems some protect against poisons, snakes, diseases and expiate sins. And some others also contain demerits.
Just like in Ayurveda certain herbs and plants are known to have beneficial effects, so also in astrology certain gems and stones are known to have good effects. But scriptures describe they must be delicately prepared and should be genuine in order to work. So good gems may not change fate or destiny of a person, but they do have some level of positive influence upon the bearer as per the scriptures.