Lord Shiva was tasked by Goddess Parvati with describing the numerous significant Shiv Lings in Kashi. One of those shiv lings is “dharmeshwar”.
Legend
According to what Lord Shiva told her, Yam Raj once built a Ling and did extreme penance in Anand Van (Kashi), where he prayed to Lord Shiva. He continued to pray even throughout the sweltering summers and bitterly frigid winters. His prayers become progressively more intense; he stood on one leg for numerous years while praying before standing on one toe for several days as part of his penance. Finally, Lord Shiva appeared in front of him and gave Yam Raj the title of Dharma Raja. (The mantra may be pronounced as Yamaya Dharma Rajaya, etc., in other mantras, such as Sandhya Vandana.)
Lord Shiva took the initiative and instructed Yam Raj to treat the dead with dignity, to punish those who commit sins, and to grant eternal life to those who carry out Punya Karma (virtuous actions). The verdict needs to be impartial. People who reside in Kashi and do pooja and other rituals ought to be cleansed of all sins committed in any generation. As such, Yam Raj is for sinners and evil people, while Dharma Raj is for righteous people.
People who bathe in Dharma Koop and worship Dharmeshwar are purified of all sins. Yam Raj consented to follow Lord Shiva’s instructions. (Chapter 78 of Kashi Khand). Even now, people still hold the view that individuals who reside in Kashi and regularly perform poojas, etc. are purified of all sins.