One way of doing it is to use Categorized symbology with the same value on both layer and then apply the same color ramp to each.
The easy case : the column with the same values on both layer is the one that you use to categorize the polygon. you juste have to use the Categorized renderer on your line layer using the same column then apply the same color ramp on both layer (or set color manualy if few categories)
The harder case : the column with the same values on both layer is NOT the one that you use to categorize the polygon. In that case you need to recover the value used to categorize the polygon and use them to categorise your line layer.
This could be done by using below expression rather than a field name for the value setting of the line layer categorized renderer.
attribute( get_feature( 'Polygon_layer_name', 'Name_of_the_column_with_same_value_in_POLYGON_layer' , attribute(@feature, 'Name_of_the_column_with_same_value_in_LINE_layer' )), 'Name_of_the_column_with_same_value_in_POLYGON_layer')
(Note that field name are used as parameter and so are between single quote rather than the usual double quote)
After entering the expression just click the Classify button and apply the same color to the line and polygon
As a side note if your line and polygon have the same color you wont be able to see the line on top of same color polygon so you may want to further alter your symbology to get something legible (below I used drop shadow but altering the the opacity or any other modification could give you acceptable result depending on your need)