How to always have the local Z axis pointing upwards in the viewport?
World Transform and Local Transform exists for reasons.

You can reset/apply your object's transform to make your Local Z axis pointing upward.  But there is no way to lock Z axis to point upward.  What you can try is to move/rotate your object's mesh in Edit mode, in there, your rotation/move operations won't change the local axis's orientation.