To most, the first thing that comes to mind when you think of an electrical ground is just a piece of metal. So what makes a ground point a ground? On any vehicle, the battery negative terminal is connected directly to the frame of the vehicle. Since the frame is solid steel/metal and conducts electricity, the entire frame essentially becomes a ground point for the battery. Okay, so why does that matter?
If your compressor is connected to the battery positive terminal, but the ground is connected to the bed of your vehicle, there's a good chance that the bed has rubber mounts between it and the frame cuasing a bad ground. Therefore, your compressor will never run as there is no 'loop' to the battery. When you ground the compressor to the frame, the metal frame allows that current to flow back to the battery negative and complete the loop. When this happens, the compressor kicks on and begins to pump air. If your compressor runs fine when connected to the battery but not when it is mounted in it's install location, the ground point could be poor/insufficient.
You can verify that your ground point is good with a multimeter/voltmeter. With your meter in hand, set the knob to read ohms. Take one probe of the meter to the negative terminal on your battery, and the other probe to the ground point you are using for your compressor/accessory. If your meter measures less than 5 ohms, your ground point should be sufficient to use. If you read more than 5 ohms with the meter, your ground point is a point of resistance and will not allow the power to flow efficiently between the battery and compressor. If the compressor runs with an ohm reading above 5, your wires will likely start to get warm from the increased resistance, which may lead to issues down the road. The more resistance, the less efficient your system becomes and your compressor will not run as intended.