Retina, 40 bytes
T`l`L`_.
(?<!_)([A-Z])
_$L$1
_(?=[A-Z])
Explanation
T`l`L`_. # Replace lowercase letters with uppercase letters when after an underscore
(?<!_)([A-Z]) # Replace any uppercase letter not following an underscore
_$L$1 # with an underscore followed by the lowercase version of that letter
_(?=[A-Z]) # Replace an underscore followed by an uppercase letter
# with nothing