(I'm new to 3d) I have been trying to fix the problem by changing the weight painting and it looks alright if I add more vertices from the leg to the feet bone, but that messes up my leg rotation.
Add a pole target bone :)
I have one, it's not visible on the image because it's so far ahead, but maybe that's the problem, I will take a look.
Yeah, it does not fix it sadly.
The armature is bending correctly, I just don't understand why the mesh of the leg doesn't follow it nicely.
Bad karma. The pole target bone is the only way that i know of that usually fixes this kind of issues. And when this does not fix it then i am out of ideas.
Well, the Blender bones system has its quirks ...
Ah, i think i have misunderstood what the problem is. I thought the bone is twisting.
It is your mesh weighting that makes trouble? It does not bend like it should? Then check weightpainting. Most probably there's a weighting from a bone that should not have influence at the leg.
Sometimes the influence is this low that you will not see it at the weightpainting overlay. But see it at a wrong mesh bending. Very low weighted vertices is nearly the same blue than the non weighted vertices. But Blender has another display type too to display the zero weights. So go through all your bones in the hierarchy and check for their weighting.