The basic reason for this is probability. The situation where two objects have the same temperature is the most likely state of the system, subject to the constraint that the energy of the total system (for example your room) is constant. This is the macroscopic state with the maximal number of microstates. Let us call this number the multiplicity $\Omega$.
This number is the product of the multiplicity of the cup and the multiplicity of the rest of the room: $\Omega = \Omega_{cup} \times \Omega_r$. The multiplicities depend very strongly on the internal energy $E$. When the cup is hot, energy is transferred to the room because the fractional increase in $\Omega_r$ is greater than the fractional decrease of the multiplicity of the cup. This makes that the total $\Omega$ increases.
Eventually, thermal equilibrium will be reached, the most probable macrostate, the state with the highest multiplicity. Then the fractional changes of $\Omega$ of the cup and of the room are equal and opposite when a small amount of energy is transferred between them. For example when the multiplicity of the cup goes up by one promille, the multiplicity of the room goes down by one promille, leaving the product unchanged at its maximum.
This is what temperature is. When two systems have the same temperature, they have the same relative change of multiplicity with energy $\frac{1}{\Omega}\frac{{\rm d}\Omega}{{\rm d}E}$. At room temperature this is about 4 % per milli-eV.
For the cognoscenti: with the definition of entropy $S = k \ln\Omega$ and $\frac{dS}{dE} = \frac{k}{\Omega} \frac{d\Omega}{dE} = \frac{1}{T}$ we recognize the fractional change of $\Omega$ with energy as the thermodynamic beta (coldness) $\beta = \frac{1}{kT} =\frac{1}{\Omega}\frac{{\rm d}\Omega}{{\rm d}E}$.