I think you touched on the fundamental reason self driving cars cannot currently do this. It would mean programming self driving cars to, in some circumstances, break the law.
I agree with the thrust of your comment though, and think that a change in the law may be required to allign incentives for machines as well as people to drive humanely.
They already do that for speed limits - iirc Waymo cars will 'go with the flow' to a certain extent if everyone around them is speeding. Swerving out of your lane (assuming it is safe to do so) to avoid a collision seems pretty straightforward.
I agree with the thrust of your comment though, and think that a change in the law may be required to allign incentives for machines as well as people to drive humanely.