How to parent an object to another one but inherit the rotation from a third object?
So the bolt needs to follow the upper leg, but to rotate when the lower leg rotates.

The copy rotation you used is good. But you need to involve an additional bone to obtain the result :



Here is the setting :


Add/extrude a new bone from the upper leg
Set it disconnected
Place its head at the center of the bolt
Align it with the lower leg bone and make sure that bolt bone and lower leg bone have the same roll (so that these two bones have the same local directions)
Assign the bolt vertices to this new/knee bolt's bone group of the mesh




Now (as you did), in pose mode, add a constraint to the knee bone like this :