According to Nature Education, restriction enzymes are used to cut DNA into smaller pieces that can then be separated by size via gel electrophoresis. Typical restriction enzymes cut DNA at four or six base pair recognition sites, resulting in very small pieces of DNA.
According to a Colorado State Biotechnology webpage, restriction enzymes are derived from bacterial enzymes that are a form of rudimentary immune system for bacteria. These enzymes evolved to cut and destroy any foreign DNA in the bacteria, which is why they cut DNA into small pieces. Restriction enzymes and gel electrophoresis are also used for DNA recombination technology, which allows for engineered genes to be swapped in and out of DNA for cloning purposes.