Why exactly does diffraction occur? Why do waves that were traveling in a straight direction change direction when passing through an opening?
I thought that the waves (red arrow) when colliding with the wall bounce in the opposite direction (green arrow).
And the waves that pass through the aperture follow its path normally as shown in the image on the right.

The waves that go in a straight direction should follow traveling straight line like a car that goes under a bridge the car is straight on the road.
But this is not so.
Why does the direction of the waves change?
How is the direction of the waves calculated?
 A: Your aperture only allows a very short segment of the incoming plane wave to pass through.  As the aperture becomes smaller, the segment looks more and more like a point source. A point source emits spherical waves like you show in your lower right figure. (this is almost intuitively obvious because of symmetry--what other shape of wave would a point emit?). 
This is usually explained more formally via diffraction:
https://isaacphysics.org/concepts/cp_diffraction
"Diffraction is the spreading out of waves as they pass through an aperture or around objects. ... In an aperture with width smaller than the wavelength, the wave transmitted through the aperture spreads all the way round and behaves like a point source of waves (they spread out below)"
A: A quick answer would be that they are not changing direction. 
Each point in the plane is the source of a single  wave. Single waves expand in circles, but as you put many single waves together you sum them and get a plane wave.
The aperture if small enough simply blocks the other waves allowing only one to pass and thus it re-takes circular shape.
This is a simplification of diffraction and huygens' principle but it might help you get an idea.
A: Tausif commented:

I think OP wants to know why the diffraction occurs and why the waves don't just continue like they pointed out in the diagram.

In any elastic medium, a pressure effect not only leads to material displacement in this direction, but also to lateral displacement. (In an inelastic medium the material gets simply punched out.) So the awaited longitudinal wave is accompanied always by a transversal wave.
This transversal wave spread out in isotropic media as a spherical wave. The obstacle with the slit limiting the isotropy and instead of a spherical wave on get only have of a spherecal wave.
A: For the full math, you can look up 'diffraction' and 'Huygens Principle' but here I will just post a quick observation that is enough to get a good physical intuition.
Suppose we are considering water waves, and imagine yourself sitting behind the barrier in the 'harbour' (at the lower part of your diagram), watching the waves approaching from 'out at sea' (i.e. the top of your diagram). As the waves reach the 'harbour mouth' (i.e. the small opening in your diagram) the water there is caused to go up and down. So there is this water bobbing up and down in the small opening. Now the surface of the water nearby is going to bob up and down too, isn't it? And the ripples will spread out from there. It doesn't really matter in what direction you consider: the waves will spread out into the 'harbour' because the water at the harbour mouth is moving.
From this way of thinking, you begin to wonder why the waves out at sea are so straight! Ultimately it is because in that case you have oscillating water all along a long line, and so the water all along that long line is caused to move in synchrony.
As I say, this is not a full mathematical answer, just an attempt to give you some intuition about the physics.
A: The first thing to realize is that waves only appear to travel. But when you look at a fish in the water, it becomes clear that the water only sloshes back and forth. Waves occur because the water movements aren't all in sync, nor could they be - how would all the water molecules know to reverse at the same time? So when you have water molecules traveling on opposite directions >>^<< there's nowhere for them to go but up. That produces the wave crest. And when a bit of water locally reverses direction, the crest moves >^<<<.
Now we know that waves are really a local effect. That means the wave inside the slit has no memory where it came from. And that means it also doesn't remember in which direction it would need to travel. All directions are possible.
Now if waves do not have memory, then how do they "know" how to travel in a straight line near the beach? Well, that's not really what happens. Wave crests travel orthogonally to the crest lines. In thin slits, where there's no longer a crest line, this no longer makes sense, and that's why you get the diffraction. 
You can see how this makes sense when you look at broader slits. In the middle, there's a well-defined crest line, and you still get the straight pattern. But at both edges, you get the diffraction effects. This frays the edges of the crest lines, progressively making them sorter, until they disappear entirely. After that, you get a complex pattern of isolated peaks.
A: Your initial picture is incomplete in describing a more in-depth version of the waves.  The waves are actually not a bunch of parallel beams traveling in straight lines down the page as you show.  What there is is a superposition of point sources of energy and a single point source of energy will produce a circular wave.  Your wavefront is made up of a nearly infinite number of these point sources and it is the superposition of the waves from these point sources that combine to create a uniform wavefront.  So, when the wave comes upon an aperture it then acts like the point source that it is and the result is just like a point source of energy would act, i.e. a circular wave.
A: In the aperture the wave is no longer plane : it is the product of a rect function, which is unity in the aperture and zero outside it, and a plane wave. You can inspect which wave vectors are present by Fourier transforming this product. The result is a convolution of the transform of the rect, the so called sinc function, and the plane wave. The message is that the result is a sum of plane waves of varying direction. For a point aperture all plane waves are present with equal amplitude and phase, that is, a spherical wave. Alas this requires some elementary math to understand.
A: @Andrew Steane has already given a good answer, I just want to make the explanation more visual. First thing I want to show is the light wave diffraction, given in the image below. What You see here is the electric field intensity plot. The plane wave is released from the back of the slit which is barely visible as the dark blue region.

The occurrence of diffraction can be summarized as the wave fronts that are parallel to the incoming wave fronts are continuing to propagate as it is, but the edges of the transmitted wave produce secondary wave fronts that are the observed, diffraction effect. To visualize it I draw the second image below, which shows the wave fronts of the wave passed the diffractive slit. As easily visible on the image below, the edges of the plane wave has a secondary wave fronts.

You have asked in the question, why the plane wave don't pass the slit as a plane wave. It is because plane wave is a combination of waves that actually elongates to the infinity. If the wave front combination doesn't elongate to infinity, we will see the same bent effect on the edges as well. To give the general propagation behaviour, I added the wave propagation GIF below (simulated using FDTD method):

