This is due to the second law of thermodynamics, which states that heat energy naturally flows from a region of higher temperature to a region of lower temperature.
Think of it like this: Imagine you have two cups of water, one hot and one cold. When you mix them together, the hot water loses heat and the cold water gains heat until they reach a common, intermediate temperature.