We define temperature as average kinetic energy of atoms. We know that outer space has vacuum that is it lacks matter and hence the temperature should be 0 K. But because of CMB radiation, the temperature is not 0. But if there exists no matter then how could there be any temperature?
Although there is almost no matter in deep space, there is still radiation in deep space, and a temperature can be assigned to it. All objects in deep space will both radiate heat and absorb it from the radiation that bathes them. After a while, those objects will come into equilibrium with that radiation, and the rate of emission will then equal the rate of absorption. At that point, the temperature of the object will equal the temperature of the radiation.