I am currently studying How excavators work? and came to know that "In excavators diesel engine is used to drive the hydraulic pump. The high pressure fluid from hydraulic pump is used to run the hydraulic motors which rotates the wheel." Is there any specific reason for using hydraulic motors instead of directly using diesel engine?
Yes, because many or most excavators can 360 rotate so getting a classic gearbox/ prop shaft drive to the wherls or tracks would be challenging.
Then sorting the ability to do forwards with one side and reverse at the same time with the other is also difficult without hydraulics.
A hydraulic motor has much greater torque density (torque vs size) compared to electric or diesel engines.
The hydraulic motor works well underwater, while an electric motor needs expensive (and heat retaining) waterproofing and a diesel engine needs air.
The hydraulic motor is simply more durable and efficient, despite any loss from converting from one power source to another.