It keeps dirt, water away from the piston and caliper cavity.
Actually the square piston O-ring retracts the piston slightly when brakes are released.
When you apply air or fluid to push piston out, put a piece of wood where the pads were to cushion the piston when it pops out. Keep your fingers out of there.
Disc brake pad retraction is primarily achieved by the elastic deformation of the rubber square-cut seal around the caliper piston, which pulls the piston back roughly 0.0001 inches when hydraulic pressure is released, creating a small, necessary clearance. This "roll back" mechanism prevents constant dragging, while also allowing the piston to slide forward to compensate for pad wear.