What is the reason why dihedrals are used when building a plane?
Because when an airplane rolls to a bank angle, the airplane begins to slip toward the lowered wing.  If the wings are mounted with a dihedral, this causes two things:  the inside wing will experience an increased angle of attack, and the outside wing experiences a decrease in angle of attack.  This combination causes an imbalance in the lift forces on the wings resulting in a rolling moment about the center of mass and returning the airplane to a wings level condition.
Dihedral angle is much more common on low wing airplanes, since the location of the CG above the CL creates a static unstable roll condition when the airplane is banked.  Dihedral angle can be used on high wing aircraft as well to enhance roll stability along with the pendulum effect of the CG below the CL e.g. a Cessna 172 still employs a slight dihedral angle to its wings.
In the age of digital flight control systems dihedral angles to wings are not absolutely necessary, though for light airplanes and gliders it’s far more elegant to design the airplane with a slight natural static and dynamic stability in all three axes.  Aircraft designers also work to ensure that airplanes have more authoritative directional stability than lateral stability from a dihedral angle to prevent unwanted Dutch rolling tendencies.