First, I’m not sure why you’re using empties in this rig. All that extra stuff makes it very hard to select things. The fact that everything in this scene is enormous also tends to make it a little hard to select the right thing on the first try. But the reason for your knee popping that way is that your leg is perfectly straight with no directional target.
For an IK leg, it’s best to give the knee a slight bend in the right direction to show the solver the preferred way to bend (as if your character is ever so slightly crouched. Also best to model your mesh in the same way). Second, an IK leg should always have a pole target. This is a bone (or an empty if you insist, I suppose. But seriously, just use bones) that floats in space out in front of the knee and tells the leg which direction it’s pointing. In the IK constraint there’s a box for this target to be specified. You may have to mess with the pole angle value to keep it from popping off in some other direction initially, but once you have it set to the right value for whatever rotation you’ve given the pole target bone, the knee will always try to point at that target, so even if you turn the leg to one side, it will still bend properly.