Forces on piston When we heat any container containing a gas fitted with a piston, a part of the heat energy increases its internal energy and the rest does work on the piston.
But when the gas does work the piston, the piston acquires a velocity. How will the piston will return to rest after getting a velocity? If the outer atmosphere is present, the outer air pressure will oppose the motion of the piston and when the external pressure becomes equal to the internal pressure, the piston will have net force 0 acting on it.  However, it'll still have a velocity, so it will move a bit further and then start oscillating. How will it come to rest? I have studied that the piston will come to rest in one of my books
 A: When we talk about thermodynamic changes we almost always assume they happen reversibly, that is infinitely slowly. In this context we mean we increase the temperature by a tiny amount and in response the piston moves out a tiny amount at a negligibly small speed. We keep repeating this until the temperature has risen by the amount we want. The piston speed remains effectively zero throughout the process, so the piston speed is effectively zero after the temperature rise has been completed.
Obviously this is an idealised process and in real life the temperature rises at a rate greater than zero. However in real life there are always sources of damping e.g. viscosity of the gas and friction in the cylinder, and these will bring the piston to a halt.
A good real life example is a car engine. The temperature in the cylinder is raised suddenly when the fuel burns and as a result the piston goes shooting outwards. Suppose the cylinder were infinitely long, and the piston not connected to anything. Then the piston would carry on travelling outwards until the pressure in the cylinder was less than atmospheric, at which point it would start slowing down, eventually stop and then travel back again. In the absense of any frictional or damping forces the piston would oscillate forever.
A: The piston will indeed overshoot its equilibrium position and oscillate.  But, the oscillations will be damped by viscous stresses within the gas, which are only significant during the rapid deformations (i.e., rapid volume changes) characteristic of an irreversible expansion or compression.  This situation is very analogous to a mass connected in series with a combination of spring and dashpot.  In the end, the the piston will settle at the equilibrium position.  The kinetic energy of the piston has been dissipated by viscous stresses, accompanied by an increase in the gas temperature, over and above that which would be calculated for reversible expansion.
