Understanding the critical temperature on a $pV$ diagram I know that the critical temperature is the highest possible temperature before a liquid becomes a gas. I also know that at the critical volume on the critical temperature isotherm, $\frac{\partial P}{\partial V}=0$ and $\frac{\partial^2 P}{\partial V^2}=0$. I don't see the relationship between the first fact and the second pair.
Surely there are many cold liquids that have a smaller volume than their container, and changing the volume of the container would therefore not affect the pressure of the liquid (until the volume of the container becomes less than the liquid), and therefore $\frac{\partial P}{\partial V}=0$ and $\frac{\partial^2 P}{\partial V^2}=0$ would be true despite not being at the critical temperature.
 A: A fluid, such as a Van der Waals gas, might either be stable, meaning that it always contracts when pressure is increased, or it might have a region of instability for which increasing pressure increases the volume. Typically, the instability occurs at low rather than high temperatures.
Consider a temperature such that the gas has an instability. Then, as volume increases, the pressure at first decreases, then increases (in the unstable region) then returns to decreasing. At each of the two aforementioned transitions between stable and unstable, the gradient of pressure with respect to volume at constant temperature vanishes:
$$\left(\frac{\partial P}{\partial V}\right)_T = 0.$$
Now imagine that one raises the temperature until this unstable region vanishes. As it does so, the two points at which the above conditions are met draw nearer until they coincide. In the same way that two simple roots draw near to become a root of multiplicity two, this means that the second derivative must vanish:
$$\left(\frac{\partial^2 P}{\partial V^2}\right)_T = 0.$$
By definition, this point at which the instability vanishes (or appears, depending on which direction you're going) is the critical point, and so the temperature, pressure and volume here are the critical temperature, pressure and volume. Hence, at the critical temperature, there is some volume at which the conditions
$$\left(\frac{\partial P}{\partial V}\right)_T = 0,$$
$$\left(\frac{\partial^2 P}{\partial V^2}\right)_T = 0,$$
are obeyed.
A: I'll split my answer into two parts since the question touches two related but different issues.

Relationship between the highest possible temperature before a liquid
becomes a gas and vanishing of $\left(\frac{\partial P}{\partial
V}\right)_T$ and $\left(\frac{\partial^2 P}{\partial V^2}\right)_T$.

From a mathematical perspective, the points where the first derivative of a function vanishes are critical points because they mark where the behavior of the function changes. In particular, if we have a family of smooth functions, a horizontal inflection point, where first and second derivatives vanish, marks the passage from strictly monotonic to non-strictly monotonic functions. In the case of the liquid-vapor phase transition, the isotherms go from smooth monotonic curves to the non-analytic isotherms with two non-analytic points at the boundary of the coexistence region. Between these two points, the isotherms are horizontal lines (see the following image from Wikipedia).

The region to the left of the coexistence line (in blue) corresponds to a homogeneous liquid (small volume = high density). The region to the right of the red curve corresponds to the homogeneous vapor (high volume = low density). The horizontal part of the isotherms corresponds to a heterogeneous coexistence of liquid and vapor at the same pressure. It is the physical requirement of coexistence at the same pressure which requires the vanishing of the second derivative at the critical point since it is the ending point of the set of horizontal isotherms.

In liquids that have a smaller volume than their container, $\frac{\partial P}{\partial V}=0$ and $\frac{\partial^2 P}{\partial V^2}=0$ would be true despite not being at the critical temperature.

It is true. It is just a trivial consequence of the previous discussion. If we put a given volume of liquid in a not too large container, at equilibrium, only part of the liquid becomes a vapor coexisting with the remaining liquid at a pressure below the critical pressure. Therefore, being in the horizontal part of the isotherms, all the derivatives of pressure with respect to the volume vanish. However, there is no contradiction with the definition of the critical point. That is the unique point on the critical isotherm where $\frac{\partial P}{\partial V}=0$.
