While I may be wrong, I would surmise that Ukraine are attempting to hold Bakhmut for as long as they can for three key reasons.
In terms of tactical reasoning, the city is a central piece of the local road network, which will help Russia to use it as a staging post; likewise, it'll limit Ukraine.
Additionally, maintaining Bakhmut may allow Ukraine to be preparing defences to the west of the city, because to fall back now may leave the line vulnerable.
Lastly, which is less tactical and more to do with overall moral, losing the city would be a significant blow to Ukraine and may embolden Russia.
Therefore, regrettably, the meat grinder may be worth it in the wider sense.