A couple ways.
They give it to themselves. Every Joseon Korean King styled himself "the Great"
Others give it to them. Kings in Europe took their epithets personally and knew what they were in many cases. They all wanted a name like "the Bold", "the Good", "the Brave", or "the Great", or in rare cases "the Lionheart". Richard probably got a little woody when he heard the last one for the first time. It became standard practice for courtiers to assign such names and for even ordinary people to come up with ways to describe their King. Lots of them were neutral, like "Barbarossa" (Red Beard). Others, like "the Thunderbolt", referring to Bayezid of the Ottomans, were very accurate and referred to specific events, like Bayezid's racing his army between Europe and Asia.
The state officially assigned names to monarchs and minted them on coins. Islamic countries did this a lot, with every Ottoman Sultan styling himself "Gazi" or some positive epithet.
Historians and literati ascribe epithets after the reign of the monarch. No doubt very few would dare call Ethelred "the Unready" during his reign. That was an epithet made popular by later historians of England writing about their own country. The same case was for Timur the Lame, who in his day was called Timur the Great.
Usually it starts with courtiers or literati genuinely praising a King or coming up with a witty, ironic epithet like "the Confessor". Then, it either catches on with contemporaries at the time, or with later writers.