Matthijs de Ligt's thunderous 51st-minute strike saw Bayern Munich get revenge over Freiburg after cup defeat.