Peterborough had the better of the opening 45 minutes and they were in front at the interval courtesy of an own goal from Stockport skipper Michael Raynes.
The big centre-back could only divert a low Aaron Mclean cross past goalkeeper Owain fon Williams, who had been busy in the opening 10 minutes when he was twice called upon to keep out efforts from Craig Mackail-Smith.
The hosts levelled matters seven minutes after the restart. Tommy Rowe's corner wasn't cleared and Pilkington smashed the loose ball home off the inside of the post.
Peterborough went back in front after 62 minutes when George Boyd crossed for Mackail-Smith and he brilliantly volleyed home.
James Tunnicliffe's own goal, following Shaun Batt's dangerous cross, made it 3-1 with 15 minutes to go.