The second law of thermodynamics says that heat cannot spontaneously flow from a colder to a hotter reservoir but only with the expenditure of mechanical energy. This is taken as a postulate or law in thermodynamics. Is there a deeper reason (probably from statistical mechanics) for why this is so?
2 Answers
Well, technically the energy can flow from a colder to a hotter object. There is no physical law that forbids it. However the probability for this to happen is so low that in reality we never see it. You can imagine that 2 objects (let's assume they have the same mass) are made of springs (basically the molecules) and each of the body has a number of energy quanta (so the colder one has less quanta). When you put them in contact, the total number of quanta (the sum of the 2 bodies quanta) can now spread on the total number of springs of the 2 bodies. So you can do some basic combinatorics, to check how you can distribute these quanta on the springs. If you do that you will see that there are many more combinations if you distribute the quanta equally on the 2 bodies (so thus quanta from the hotter body has to go to the colder one, and this is basically the heat flow), then if you add some quanta from the cold one to the hotter one. In objects of the sizes we are used to there are something of the order $10^{23}$ molecules (springs) so the probability of a quanta going from a cold to a hot one is so incredibly small that you never see it in real world. So there is no law that forces the heat to go from a hot to a cold body, it is just that it is much more likely for that to happen.
All bodies radiate heat according the the black body distribution for the temperature they are at.
This radiation is energy transferred radially away from the bodies , and its magnitude is given by the Stephan Boltzmann law . The radiance (watts per square metre per steradian) is proportional to the fourth power of the temperature. Thus a colder body will radiate to the hot body much less than the hot body to the cold. As the hot body will be cooling by its radiation, the rate of cooling will be less than it would be if there were no cold radiator close to it. On the other hand as the incoming radiation from the hot body is much larger than the loss of the cold body's black body radiation, the cold body will get heated.
Maybe the quantum mechanical picture, or radiation being photons of energy h*nu will help also. Many more photons of higher energy impinge from the hot body to the cold one, than from the cold body to the hot one.
Edit after the question was made duplicate
When one is studying physics one has to keep in mind what it is all about:it is a discipline that uses mathematical models to describe and predict data/measurements. The mathematical equations used in order to do so have an unlimited number of solutions that are irrelevant and contradictory to data. Laws, postulates, principles are distillation of observations and measurements which are imposed like axioms to the mathematics, so as to pick up the subset of the functions that describe and predict measurements and observations.
In mathematics, axioms can be replaced by theorems which then are provable by the new axioms; in the same way postulates and laws and principles can be replaced by theorems , mathematical structures, but the explanation is circular, the same as replacing axioms in mathematics.
In this answer I am using data , black body radiation, to "explain" why the law had to be assumed.