Why does only linear motion of the molecules contribute to temperature? In my physics class I studied that it is only the linear motion of the molecules and not the rotation of the molecules that contributes to the temperature. But why is that?
I studied that temperature is basically the average kinetic energy. When a molecule moves it has translational kinetic energy and so it contributes to temperature. But when a molecule rotates it has rotational kinetic energy. So shouldn't it contribute to temperature as well? What makes rotation not contribute to temperature and motion contribute to temperature?
 A: You are right. Each degree of freedom contributes to the total energy. But, in a classical framework, there is the equipartition theorem which indicates that each degree of freedom contributes for $\frac{1}{2}kT$.
For the kinetic energy, we have three degrees of translation and the contribution for the kinetic  energy is $N\frac{3}{2}kT$. In this sense, we can say that the temperature "measures" the kinetic energy of the gas.
But one can apply the reasoning to the terms of rotation with, in general (there are subtleties...) , three degrees of freedom. the contribution for the rotationnal energy is still $N\frac{3}{2}kT$ And so, one could say that temperature "measures" the rotational energy of molecules.
A: 
But when a molecule rotates it has rotational kinetic energy. So
shouldn't it contribute to temperature as well?

It can, but when it does it does so, it does so indirectly.
An example is raising the temperature of water in a microwave oven. Microwave ovens primarily operate at 2450 MHz. The rapidly alternating electric field causes the polar water molecule to rotate. The rotational KE acquired from absorbing microwave energy is then randomized into translational KE when the rotating molecules collide with the molecules in translational motion. The result is an increase in the temperature of the water.
So the temperature of the water is still based on the translational KE of the water molecules. But in the case of the microwave oven that translational KE is increased due to randomization of rotational KE. Thus in the example of microwave cooking rotational KE is contributing to an increase in temperature, though indirectly.
Hope this helps.
A: It is not true that only the kinetic energy of translational motion of the molecules contributes to temperature. If it was true, there could be no difference between specific heats of mono- or diatomic molecules.
The reason two other answers appeared at the moment I ended writing my answer say the opposite is related to the possibility of defining the temperature as proportional to the translational kinetic energy alone, although I think in this way the connection between temperature and internal energy gets obfuscated and, more important, one is introducing an experimentally inaccessible translational-only kinetic energy.
The key point is that temperature is not the sum of different contributions. The internal energy can be seen as the sum of contributions from different degrees of freedom. For a gas in the classical regime, each contribution is proportional to the temperature. Therefore, even the energy of a single degree of freedom could be considered as a probe of the temperature.
There are at least three separate issues that should be clarified to understand completely the relation between temperature and internal energy of gases. The resulting picture may help to understand the reasons for claims that under some circumstances only the translational degrees of freedom contribute to the temperature.

*

*Only in the case of gases in classical regime (i.e., when quantum effects are negligible), temperature can be defined as $\frac{2}{k_B}$ times the internal energy per each degree contributing to the Hamiltonian with a quadratic term. This is the result of a theorem (Equipartition of the energy) of Classical Statistical Mechanics. For a monoatomic gas, the theorem states that the internal energy of a system of a monoatomic gas is
$$
U=\frac{3}{2}N k_BT.
$$
For a di-atomic gas, if the temperature is such that $k_BT > \Delta E_r$, where $ 
\Delta E_r$ is the spacing between rotational levels, we have
$$
U=\frac{5}{2}N k_BT.
$$
Notice that rotational states of a diatomic molecule involve only two additional quadratic terms in the Hamiltonian. For a polyatomic molecule, treated as a rigid body, the factor 5 becomes 6 (three rotationally degrees of freedom).


*At low temperatures (when $k_BT$ is comparable or lower than $\Delta E_r$), the rotational degrees of freedom do not contribute to the internal energy. In this case, one could say that temperature is controlled only by translational degrees of freedom.


*Even if the difference is negligible for macroscopic systems, one should remember that global translations of the center of mass or global rotations do not contribute to the temperature. Therefore, the correct formulas for a classical system of mono- and diatomic molecules should be
$$
\begin{align}
U&=\frac{3}{2}(N-1) k_BT\\
U&=\frac{5}{2}(N-1) k_BT
\end{align}
$$
if $U$ represents the internal energy of the gas and $N$ the number of molecules.
In order to make quantitative the previous remarks, notice that for a diatomic molecule $\Delta E_r \simeq \frac{\hbar^2}{2I}$, where $I$ is the momentum of inertia of the molecule. The freezing temperature for the rotational degrees of freedom of O$_2$ or N$_2$ is about 15 K. For a very light molecule like H$_2$ is about 85 K. Therefore, at room temperature, one can assume a classical behavior.
