Moving this IK bone just a little causes the leg to twist up
I don't know if it will solve all your problems but I guess you need to:


Deparent the second leg controller.
Move up a bit the central limbs so that it knows how to bend the legs.


Please tell me if it's enough to fix your problem.