When I was designing for Cat before my retirement the standard used for bolt engagement was 1.5 times the thread diameter. This was to prevent the bolt from striping out of the fastener hole if too short when being torqued. Measure the thickness of a M8-nut, this is all that is required for the clamping force to hold something tight. I doubt that has changed since then, but you never know.
Now in manufacturing most companies try and standardize on certain bolt diameters and length to allow min-max buys of material to obtain the most economical price from suppliers. So, this is why some fasteners are longer than needed for the job.