Lambert headed Peter Whittingham's inswinging cross home on 74 minutes, before he fired past Lee Camp with a deflected effort five minutes later.
The home side looked set to seal the win after taking the lead on the hour mark when Chelsea loanee Izzy Brown scored from Greg Halford's long throw.
Rotherham had enjoyed the lion's share of possession, with Danny Ward and Brown causing the Welsh side's defence problems during a dominant first-half display.
But Alan Stubbs' side were once again guilty of failing to see out the game as Cardiff came from behind to seal their first league away win of the season.
The defeat leaves United into the relegation zone after blowing the lead for the fourth game in a row.
Lambert had the first shot in anger with a long range free-kick on 14 minutes as both teams started slowly.
Dael Fry's powerful shot was well saved by Ben Amos before Brown's header was cleared for a corner by Sean Morrison.
Ward had a curling shot comfortably saved on 21 minutes as the Millers stepped up the pressure.
Ward then had an angled shot turned behind by a stretching Amos, before Brown fired just over after cutting through the Bluebirds defence.
Joe Ralls hit a thunderous effort a yard over Camp's crossbar with Cardiff's best chance of the half on 33 minutes.
Morrison failed to direct his header on goal on 37 minutes as Cardiff enjoyed a better spell of possession.
Morrison put his head on the line at the other just before half-time to clear Halford's inswinging cross as Ward waited to pounce.
Ward and Brown combined well just after the restart to force another corner for the Yorkshire side.
Ralls tried his luck from distance on 54 minute as struggling Cardiff were limited to speculative long-range efforts.
City captain Morrison blocked another Ward shot as the former Huddersfield Town team-mates continued to enjoy a fine personal battle.
Rotherham finally went ahead when Brown pounced after Halford's long throw created an opening on 60 minutes.
Morrison and Matthew Connolly both headed over as City looked for a quick response.
Kelvin Wilson missed a chance to wrap up the points when he headed straight at Amos on 70 minutes.
Lambert showed good strength to hold off Halford and Wilson as he headed over a minute later.
But he found the back of the net on 74 minutes to draw Cardiff level after heading home Whittingham's free-kick.
And battling Cardiff completed an impressive turnaround when a Lambert shot deflected past Camp with 11 minutes remaining.
Rotherham: Camp, Fisher, Mattock, Fry, Wilson, Taylor, Halford, Frecklington, Newell (Blackstock 82), Brown, Ward
Cardiff: Amos, Peltier (Manga 88), Morrison, Richards, Connolly, Ralls (Harris 70), Noone, Whittingham, O’Keefe, Lambert, Immers
Referee: David Coote (Notts)
Attendance: 8,448 (390 City)