In the basic closed guard, a practitioner hooks their legs behind the back of their opponent. This in essence prevents their adversary from improving to a better position on top of them or walking away. There are many variations to the basic closed guard as well, depending on the clothing involved, hand use, and purpose of the situation. In this case, notice how the man in the guard is controlling his opponent's head from the back with his right hand and his opponents' arm by hooking his left arm around it. By keeping his opponent that close, he has effectively taken away his ability to strike or punch him with power. This is very important in real fighting and MMA.
The guard is not solely a position of defense, however. When learning Brazilian Jiu Jitsu or submission fighting, practitioners discover how to open their guard to set up submissions(armbars, choke holds, and more).