Renaming multiple layers in the legend from an attribute in each layer in QGIS

You can use a script like this:

layers = QgsProject.instance().mapLayers().values()

for layer in layers:
    # get the first feature's UNIT_NAME value
    name = layer.getFeature(0)["UNIT_NAME"]
    layer.setName(name)

Note: The script changes the name of the single layer that has 72 categories, too, if it exists in Layers panel. So you can add an if statement to pass that layer.

layers = QgsProject.instance().mapLayers().values()

for layer in layers:
    if layer.name() == "NAME_OF_THE_SINGLE_LAYER":
        continue

    name = layer.getFeature(0)["UNIT_NAME"]
    layer.setName(name)

So extending Kadir's answer, because I did not want all layers to be renamed, just those that got assigned names with a specific string through affine transform, I came up with the following, which worked nicely.

import re
RES_STRING='Palinspastic'
STRING=re.compile(RES_STRING)
layers = QgsProject.instance().mapLayers().values()
for layer in layers:
    LAYER_NAME=layer.name()
    if STRING.search(LAYER_NAME):
        name = layer.getFeature(0)["UNIT_NAME"]
        layer.setName(name)