Your excellent "concerned" comment to @Themis makes me write this but it is too long for a comment itself. You wrote:
If I make a large change for the piston, I imagine there will be an abrupt relaxation to equilibrium and this will be related to large dissipation. But If I make many quasi-static changes, then at each change the dissipation should be small, such that at the end more energy is extracted. But the problem is that I do not see any physical picture or equation why the sum of the very small amounts of dissipated energies during the sequence of quasi-static changes should be smaller than the amount of dissipated energy during the one abrupt change.
Now in your original question you have asked why the work is maximal for a reversible process. Stated more precisely: why the work done between two equilibrium states is maximal for an adiabatic reversible process connecting those states. Sears and Kestin showed that when phrased this way the statement is essentially equivalent to the various formulations of the 2nd law of thermodynamics by Carnot, Kelvin, Clausius, Caratheodory, etc. You can find very readable descriptions of this view of the 2nd law in Pau-Chang Lu:"Didactic remarks on the Sears-Kestin statement of the second law of thermodynamics," https://doi.org/10.1119/1.13048, and in Zemansky:"Kelvin and Caratheodory-A Reconciliation", https://doi.org/10.1119/1.1972279
Returning to your question, as a warm-up, remember that there is the number zero, and all positive numbers are larger than zero but none of them is zero, and there is no smallest positive number. Regarding reversible processes, in short, there is no reversible process. This I am stating in the same sense as that there is no smallest positive number. Instead, all processes are irreversible.
If you take two equilibrium states, say $\mathfrak{S_1,S_2}$ whose deformation (mechanical, electrical, magnetic, chemical, etc.) variables are the same, then one is accessible from the other via an adiabatic process, $\mathfrak{S_1} \to_{ad} \mathfrak{S_2}$. The measurable difference between the two states could be the experimental temperature: one is higher than the other, the higher being accessible from the lower one, and not vice versa. This you can take it as an experimental fact (Joule's paddle wheel) and then also as an axiom that can help define what we mean by reversible for this kind of thermodynamic system.
We would like to say that a reversible process is the one for which the work expended in the almost cyclic process $\mathfrak{S_1} \to_{ad} \mathfrak{S_2}$ is the smallest but reversible processes do not exist. Instead we can look for a class of irreversible processes for which the work $\mathcal P_n := \mathfrak{S_1} \to_{ad}^n \mathfrak{S_2}$ is say monotonically decreasing $W[\mathcal P_n] \ge W[\mathcal P_{n+1}]$ and $\lim_{n\to\infty} W[\mathcal P_n] =0$. All the processes of $\mathcal P_n$ are irreversible but in the limit they approach a non-existent reversible process that we can arbitrarily closely approximate but one we cannot reach. That is ok, because we do not have to.
Notice that this way we actually postulate that an adiabatic process can never be cyclic, it can approach, in the limit, a cyclic process but can never reach one. As I have said above those fictitious limit processes are really classes of real processes in a similar sense as one can define generalized functions, ie., distributions, as classes of functions, see George Temple:"The theory of generalized functions", https://doi.org/10.1098/rspa.1955.0042.
Having found the reversible processes that can make adiabatic cycles, we will have also found the isentropic surfaces these cycles are embedded in after which we still have to define non-cyclic reversible processes connecting states with different deformation variables; read Pau-Chang Lu and Zemansky.
What does all this have to do with the approximating processes being quasi-static? That comes in because we are connecting equilibrium states with the minimum of effort, ie., work expended, or, if you wish, with the maximum of "result" that is work gained. In either case, because of the optimality of the ideal process it must also be optimum between the starting point and any equilibrium point along the optimum process. Does such intermediate equilibrium point always exist? It does not have to; instead all we need is that there be equilibrium states of the same experimental temperature and deformation parameters as the ones along the process, and that is enough because the work is defined by the progression of those parameters. We break up the required process into segments whose ends are equilibrium points and in between those neighboring endpoints we approximate the reversible process needed by a class of irreversible processes. Since this class by definition is smaller than the one connecting the initial and final points there is no guarantee, as you have noted in your comment, that the total irreversibility, ie., dissipation is less than the other but both classes are lower bounded by the same smallest expended work that moves from one end to the other. What a quasi-static process, ie., one with many equilibrium states does is to assure us that we can approach, at least in principle, the reversible one if it is possible to approach it at all.
There are several places where all these ideas can fail, for example, we have assumed that any two equilibrium states can be connected by some adiabatic process, this does not have to be true. Also the existence of equilibrium states themselves can be questionable. Common examples for which no reversible processes can be conceived are plastic deformation and ferromagnetic hysteresis, or @AndrewSteane's toothpaste. Even if thermodynamic states can be defined those are all surrounded by a sea of essential irreversibility. For a hysteretic cyclic process, if it is demanded that the process contain at least two fixed distinct states, $\liminf_{n\to\infty} W[\mathcal P_n] > 0$, always.
quasistatic reversible
yields many discussions on this topic. $\endgroup$