They probably use the memory palace technique. Each line can be thought of as a picture that reminds them of the line. Then you place that picture inside a fake palace or museum in your mind. Then you take a tour of the museum or palace in your head and you remember the lines. The technique is also used to remember large numbers like pi.
It really amazes me how theater actors are able to memorize an entire play.
They probably use the memory palace technique. Each line can be thought of as a picture that reminds them of the line. Then you place that picture inside a fake palace or museum in your mind. Then you take a tour of the museum or palace in your head and you remember the lines. The technique is also used to remember large numbers like pi.