Why do we use external pressure to find force exerted by gas on a piston in a closed vessel during its expansion?
For a frictionless, massless piston, the force per unit area that the gas exerts on the inner face of the piston is always equal to the force per unit area applied on the outer face of the piston (since the piston is massless, ma = 0).  However, for an irreversible process, the force per unit area exerted by the gas at the interface is composed both of the "thermodynamic pressure"  that one could determine from the equation of state for the gas (e.g., the ideal gas law) applied locally at the interface,  plus "viscous stresses" in the gas that are determined by the rate at which the gas is deforming.  Furthermore, if the expansion or compression is rapid enough, the conditions within the cylinder are not even uniform spatially.  So figuring out the force per unit area that the gas exerts at the interface for irreversible expansion is problematic.  However, fortunately, if the force per unit area on the outside is specified by manually imposing a force per unit area (e.g., if the atmosphere is imposing the pressure outside), the work done by the gas on the surroundings can still be determined.  This is because the force per unit area exerted by the gas at the interface will adjust to always match the force per unit are on the outside (again, since the piston is massless and ma = 0).

In the case of a reversible process, the situation is much simpler, since here, viscous stresses are negligible, and the force that the gas exerts per unit area on the inner face of the piston can be determined by applying the ideal gas law (or real gas equation of state) to the spatially homogeneous gas in the cylinder.  In this case, however, the force imposed on the outside must be controlled very carefully, so that it differs only slightly from the average inside gas pressure during the entire expansion or compression (and the gas pressure within the cylinder remains essentially uniform spatially).