How to dynamically adjust the angle of a bone to make it point in the correct direction

if you want the skeleton to roughly face the target i actually modify spine_03, although this does depend on your animations

if its just the weapon i do recommend fixing the socket and then adjusting your weapon mesh so the barrel faces forward, (X axis) just for consistency

if its just for bullets then it doesnt really matter, if you just trace from Muzzle to Target and use the UnitDirection it should be fine

another option is to look into the ControlRig which has an inbuilt Aim function