when flipping on the horizontal axis the sprite's left foot would be inside the wall.
yeah exactly, because it is not symmetrical.
just move the collision rectangle on the foots so that its center is positionated on the center of the character node, in this way the AABB rectangle will be positionated exactly in the same position when flipped, instead of slighlty translated.
you wont need any raycast then.
the other thing you can do is to flip the sprite only, and do not touch the collision poligon on the bottom.