What can I do to make the hand hold the grip of the gun even while the character is bending downward or upward?

If the AimOffset poses you’re using have the ik joints ( ik_hand_l/r ) that are following the hand_l/r, you can simply use a two bone ik node after the AimOffset node, where you set the hand_l/r position using the bone space from ik_hand_l/r.
By doing that you’re fixing the AimOffset lack of precision by forcing the hands towards where they should be.