Glaucon's point is to isolate a question: would anyone, given complete impunity, choose to act justly? If justice is merely a social contract — something we observe only because we fear punishment and want reputation — then the person with the ring has no reason to be just. They can have all the goods of injustice without any of the costs.
Glaucon extends the thought experiment into two ideals. Imagine the perfectly unjust man: commits every injustice while maintaining a flawless reputation for justice. Now imagine the perfectly just man: does every just act while bearing the reputation of being unjust — whipped, tortured, crucified. Which life is better? If justice is worth having only for its rewards, the unjust man wins.
This is the challenge the rest of The Republic is designed to meet. Plato's answer is that the just person's soul is ordered and flourishing while the unjust person's is disordered and wretched — regardless of reputation. Justice is not a burden we endure for external rewards; it is what the soul's health consists in. The Ring of Gyges scenario only seems to favour injustice if you mistake reputation for reality and confuse wealth with wellbeing.
The Ring of Gyges story appears in Book II and draws on the historical legend of Gyges of Lydia, recorded by Herodotus. It is one of philosophy's most enduring thought experiments about the foundations of morality.