When I place a piston like shown at the screenshots they glitch out after a few seconds (it happens with sideways pistons too). This bug also happened when I tried to make an automatic cocoa bean harvester. It has been around sice at least minecraft 1.2.5
Duplicate of MC-127.
Edit: Sorry copied full response^^