There is a tool Menu Processing / Toolbox / Topological coloring
, however only for polygons, not lines. You could still use it:
Create a (small) buffer around your lines.
Apply
Topological coloring
: it will create a new attributecolor_id
Use Categorized styling and set the color to the field
color_id