Its called refraction. Theres not much more to it than what you see. The light you see got bent like a fun house mirror as it passed through the glass and water, which is why the arrow appears flipped. It's because water is refractive, moreso than glass. The circular shape of the glass turns it into a circular lens that creates the most distortion possible. Pic related shows a sphere with its refractive index increasing.
When you put your hand in deep water and it looks like its in the wrong place, its the same thing. The surface of tbe water ks flat tho, so it just looks like its shifted in one direction relative to where you are looking from.