Why and how is sound produced when two objects hit each other?
Sound is longitudinal pressure waves in the air, It can be produced in a couple of ways in a collision.
The impact can set up pressure waves and or ringing in the bodies themselves which then interact with the surrounding medium to produce audible sounds. This is the mechanism of a bell.
If enough air is forced out of the space between the two bodies as they approach sound can be made either directly (the displacement is the initiating event) or a secondary effect of that out-rushing air interacting with the edges of the bodies. This mechanism is rare enough in everyday life that I can't think of an example off the top of my head.