Let's start with the standard basis frame: [1, 0, 0], [0, 1, 0], and [0, 0, 1].
Imagine this frame goes through some arbitrary rotation R, with one constraint, that we know that after the R is applied to the frame, the z-axis becomes [0, 0, -1].
I want to calculate a rotation that "flips" the [0, 0, -1] back to the [0, 0, 1] vector with the smallest angle possible. Note: Inverting the R is NOT correct, because we want the smallest angle, and inverting R would always completely erase the rotation to give us the identity matrix.
The top answer here: Calculate Rotation Matrix to align Vector A to Vector B in 3d? does not apply, because I am describing the edge case that Jur van den Berg says is not supported.
Geometrically, if we start with the orientation corresponding with the z-axis at [0, 0, -1], I think to "flip" the frame we need to swap the corresponding x and y axises, and simply multiply [0, 0, -1] by -1 to get [0, 0, 1]. You can understand what I'm saying if you use your hand to form a frame by right hand rule, then 'flip' your thumb to negate the z-axis, and then 'flip' it back. How do I calculate this 'flip' relative rotation for any arbitrary orientation?