Bayern, who have all but secured the Bundesliga title and are chasing a 20th German Cup crown, were unstoppable in the first half and an unmarked Ivan Perisic headed in a Thomas Muller cross for the lead in the 14th minute.
"In the first half we should have scored more goals. In the second half we did not do it well," Bayern coach Hansi Flick said.
"But it was a Cup game and at the end it was a deserved qualification. It could have been an easier second half if we had done it better in the first."
Frankfurt, who beat Bayern in the 2018 final, came out transformed after the break and snatched an equaliser through substitute Danny da Costa in the 69th.
Yet Lewandowski scored the winner five minutes later with Bayern's only real chance in the second half after confusion in the Frankfurt box and following a VAR review.