Why does change in speed of a wave make it refract?

The wave only refracts if it enters the medium at an angle. Follow a single wavecrest; if the wave is entering the medium at an angle, then part of the wavecrest enters the medium first, and starts to slow down, while the other part of the wavecrest is still going fast, and therefore the wavecrest must bend. If the wave enters at a right angle, then the entire wavecrest is slowed down simultaneously and no refraction occurs.

Helpful image to illustrate


There are several ways to look at it. From what you have, the easiest is to understand it as deriving from Fermat’s principle:

the path taken between two points by a ray of light is the path that can be traversed in the least time

Because light travels slower in the medium of higer refractive index (as you stated), its course will be so that it travels a smaller distance in this medium than in the other. There's a commonly-used analogy for that (apparently from Feynman):

enter image description here

The rescuer wants to reach the drowning person as fast as possible. Because he runs faster than he swims, he won't take a straight path but his optimal path follows Snell's law.