There are a handful of reasons why.
The first one is that the diesel engine has a lower RPM. It runsat a slower speed compared to petrol engines. This reduces the friction loss and provides it enough time to complete the combustion process.
Talking about the combustion process, diesel engine takes in more air. Meaning, it has more oxygen to burn the fuel. This helps reduce the wastage of fuel.
Another big reason why diesel engine has more efficiency than a petrol engine even with the same CC is because diesel contains more energy. It is much denser than petrol (its same quantity weighs more). This enables it to pack more energy. Naturally, with more energy, it has its efficiency affected positively.
Compression is another reason. Due to the presence of air and clearance volume, the compression ratio is higher in a diesel engine. This helps it attain more efficiency than a petrol engine.
These are a few broad reasons why diesel engine have more efficiency than a petrol engine even when both of their CC is same.
Hope this answers your question.