The original reason for Russia to take Bakhmut was because it's a useful operational point on the way to Slovyansk and Kramatorsk, and pinching those cities out would have enveloped a decent fraction of skilled Ukrainian troops. However, the rout in Kherson and the Russian evacuation from all the towns there meant that there were no longer any forces pushing Slovyansk from the north, so the resulting operational picture no longer makes much sense.
The continued reason for Russia to take Bakhmut at that point is largely attributed to inter-service rivalry within Russia: Wagner was hell-bent on taking it, to prove greater competence than Russia military (conscript or professional) forces. Ukraine continued fighting to defend it because it gave them such favorable casualty ratios, although it has been suggested that the casualty ratio became unfavorable to Ukraine in the past few months. (Whether or not it was still a good idea for Ukraine to continue contesting Bakhmut rather than withdrawing entirely is a question that has no clear answer right now, and will be hard to properly assess likely until well after the war is over. Fog of war is hard!)
The continued reason for Russia to take Bakhmut at that point is largely attributed to inter-service rivalry within Russia: Wagner was hell-bent on taking it, to prove greater competence than Russia military (conscript or professional) forces. Ukraine continued fighting to defend it because it gave them such favorable casualty ratios, although it has been suggested that the casualty ratio became unfavorable to Ukraine in the past few months. (Whether or not it was still a good idea for Ukraine to continue contesting Bakhmut rather than withdrawing entirely is a question that has no clear answer right now, and will be hard to properly assess likely until well after the war is over. Fog of war is hard!)