I had a similar issue and it turned out to be from the original export of the 3D model I had set the forward axis to y instead of x so it made the legs twist up with IKTwoBone. I made the primary and secondary axis in the IKTwoBone to -1,0,0. Below is the thread.