Energy transformations in chemiosmosis and ATP synthase
ATP synthase is basically a pump operating in reverse: while transporters such as the Na/K ATPase uses ATP to push ions against a chemical gradient (resulting in potential energy), ATP synthase uses the H+ gradient across the mitochondrial membrane to make new ATP.

A pump uses ATP (chemical energy) to achieve one-way transport by inducing conformation changes in the protein (mechanical energy), which either opens the channel only when ions come in contact with the low-concentration side, or closes the channel when ions come in contact with the high-concentraton side. In either case, the result is that ions can pass only in one direction, and a concentration gradient will build up (potenial energy).

In the case of ATP synthase, the process is simply reversed: an H+ ion entering the channel from the high-concentration side (the intermembrane space) causes a conformation change that opens the channel, and is coupled to the synthesis of ATP. Precisely how the ATP synthase accomplishes this on the molecular level is a complicated topic, and still an active area of research. See this article for an overview.

Note that ATP synthase is clearly reversible: if the mitochondrial H+ gradient collapses, for example if respiration is blocked, then ATP synthase can run in reverse, consuming ATP to pump H+ out of the matrix. There is even an ATPase inhibiting protein dedicated to blocking the ATP synthase in this situation, to prevent the depletion of ATP. Also, the lysosomal ATPase is structurally similar, but operates in the reverse direction to create low pH in lysosomes.