Personally I think it was a planned pregnancy, as far as the scripting goes. If you think about how ironic it is on just about every level, it starts to make more sense and looks more and more intricate--too intricate to be a last-minute thing.
I say this only after having watched the entire series four times

There is so much subtext to this show you almost have to soak in it to absorb it all.
However, I haven't looked into how far ahead they plot the show. Might bear investigation.
And I admit, Peggy's pregnancy is very sudden, and when I first saw the finale I was weirded out by the abrupt revelation for sure. And you know, every time I watch one of those
I Didn't Know I Was Pregnant shows, my knee-jerk reaction is, "What, are they stupid?! Something like that, how do you not know?!" Honestly, I still have that reaction. But the more compassionate me tries to understand the circumstances and the misunderstandings these women go through.
Take Peggy for example. She was on birth control. To her, there's no way she can be pregnant, despite the affair. Also, she's trying really hard to be something other than mommy housewife during a time when all of society expects her to be
mommy housewife. She feels that a baby would totally ruin her chances of being something different than her mother, say. That's why she gets on the birth control in the first place. So to her, and I think it's quite reasonable, there's got to be another explanation. She's just been eating from the cart more, or something. Pregnancy is the last thing from her mind. And when it does cross her mind, it scares the hell out of her, but then she thinks, "No, can't be. I'm on the pill. It's impossible."
We should look into it though. Maybe Wikipedia for that episode???