The phenomenon is called "refraction". It's the process of
light waves bending toward a different direction when they
cross a boundary between different media ... in this case,
from water into air.
Your brain doesn't know that the light waves bent toward a
new direction when they came out of the water into the air,
so your brain locates the bottom half of the pencil just like it
ALWAYS does ... in the direction the light waves are coming FROM.