The width of the dopesheet and graph names is managed automatically. It increases as needed, but it doesn't not decrease automatically as you change selections because that would cause timeline position to change, making your keys jump around. That is jarring and makes working with the graph/dopesheet more difficult.
Clicking the lock icon adjusts the width to the current items. When locked the width never changes and is only as wide as necessary.
You must have some very long names to get it so wide? To reset the width, you can click the lock icon twice, to lock and unlock.
Dragging to control the width adds a tedious action that would be better to handle automatically. If the above doesn't solve your annoyance, maybe we could allow reducing the width down to a size that fits a majority of names. That way having one long name doesn't result in a high width that requires manually reducing.