Alyssa B. Sheinmel said this quote

Maybe the witch thought she was protecting Rapunzel, not punishing her. Maybe she thought that if Rapunzel was locked away, no one could ever hurt her. Maybe the witch kept Rapunzel because she loved her, because she was scared that if other people could get to Rapunzel, they would hurt her. And maybe Rapunzel didn't understand the witch; maybe she was angry at her - but maybe she loved her too.