Lewandowski struck with a 15th-minute penalty and then hammered in a free kick for his 12th goal of the campaign, with Leroy Sane, Kingsley Coman and Thomas Muller also on target in a rollercoaster encounter.
Bayern, who lost 5-0 to Borussia Monchengladbach on Wednesday in their heaviest German Cup loss ever, moved up to 25 points. But their defence, that proved so vulnerable against Gladbach, was again far from solid, angering goalkeeper Manuel Neuer, who made a string of good saves as Union kept attacking.
"We obviously wished for such a start and it really worked well in the beginning," Neuer said. "The two goals we conceded are frustrating."
"But we are satisfied that we managed to show a different performance today."
Borussia Dortmund, 2-0 winners over Cologne, are just a point behind in second place while Freiburg, playing their best ever season so far, beat Gruether Fuerth 3-1 to occupy third spot a further two points behind.
Lewandowski opened his side's account in the 15th minute with a spot kick and added a second eight minutes later before Sane made it 3-0 in the 35th, with Bayern, who face Benfica in the Champions League on Tuesday, keen to prove their midweek loss was just a blip.
But Union were far from done and pulled one back in the 43rd through Nico Giesselmann. Union's Sheraldo Becker then put the ball in the net once more two minutes later but was ruled narrowly offside.
It was the hosts who got off to a better start after the break, with Bayern's defence looking fragile and Becker and Taiwo Awoniyi time and again finding the space to threaten.
Bayern, however, struck against the run of play with Coman thumping the ball in from a tight angle just past the hour to settle the nerves somewhat.
But again Union refused to surrender, cutting the deficit once more with Julian Ryerson four minutes later before finally Mueller delivered the killer blow in the 79th.