That's a rather loose wikipedia article. This sentence from the intro paragraph is pure BS: "It is a trajectory optimization that uses gravity to steer the vehicle onto its desired trajectory." When launching from the Earth (or Mars, in the future), it's aerodynamics rather than gravity that steers the vehicle. When landing on or launching from the Moon (or in the future, some other gravitating body that has no atmosphere), the vehicle's attitude control system has to continuously reorient the vehicle so that it remains on the optimal path. Gravity does not steer the vehicle.
So what is this optimal path? The concept of a gravity turn is rather weak in that wikipedia article. I'll define a "gravity turn trajectory" as the trajectory that obeys vehicle constraints, that addresses all the forces that act on the vehicle, and that maximizes the payload mass the launch vehicle can deliver to a desired orbit. With this definition, it's tautological that a gravity turn trajectory maximizes the amount of payload that can be delivered to orbit. Alternative definitions of a "gravity turn" trajectory similarly boil down to a tautology.
That said, there is one simplifying case where one can easily compute the optimal trajectory:
To simplify things we can assume the planet as a perfect sphere, with no atmosphere.
It helps to look at specific mechanical energy. Assuming that perturbations from other gravitation bodies are very small and can be ignored, the specific mechanical energy from the perspective of a non-rotating frame centered on the planet of interest is
$$\mathcal E = \frac12 v^2 - \frac{GM}r \tag{1}$$
Differentiating with respect to time yields
$$\frac{d\mathcal E}{dt} = \vec v \cdot \dot{\vec v} + \frac{GM}{r^2}\dot r \tag2$$
The vehicle's position in spherical coordinates is $\vec r = r \hat r$. Differentiating with respect to the yields $\vec v = \dot r \hat r + r \dot \theta \hat\theta$. Thus $\dot r = (\vec v \cdot \vec r)/r$. Incorporating this in equation (2) yields
$$\frac{d\mathcal E}{dt} = \vec v \cdot \left(\dot{\vec v} + \frac{GM}{r^3}\vec r\right) \tag3$$
With only spherical gravity and thrust acting on the vehicle, the vehicle's acceleration $\dot{\vec v}$ from the perspective of a planet-centered inertial frame of reference is
$$\dot{\vec v} = \frac{\vec F}m + \vec g = \frac{\vec F}m - \frac{GM}{r^3}\vec r\tag4$$
With this, equation (3) becomes
$$\frac{d\mathcal E}{dt} = \frac{\vec v \cdot \vec F}m \tag5$$
This should make it obvious that thrusting along (against) the planet-centered inertial velocity vector is the best strategy for increasing (decreasing) specific mechanical energy. The trick then is to find the path that enables this to happen and that brings the launch vehicle to the desired orbit. This is the spherical body / no-atmosphere gravity turn trajectory.
What about launching from a planet with an atmosphere? Typically the launch vehicle flies at or close to zero angle of attack. Since the planet's atmosphere more or less rotates with the planet, angle of attack is a planet-centered, planet-fixed as opposed to a planet-centered inertial concept. A vehicle that flies at a zero angle of attack with respect to the local winds is not thrusting parallel to its planet-centered inertial velocity vector. Nonetheless, the trajectory followed is often still called a gravity turn because the planned trajectory is optimized. (Optimization is a key part of the planning.) The term is a bit tautological.