Because some cables do not meet USB spec and are unable to negotiate faster charging protocols. Faster charging protocols such as USB-PD allow higher voltages and currents which provide a greater charging power to the device and increase charging speeds.
In addition, all cables have a resistance. This is affected by the length and cross sectional area supplying the power pins.
The formula is:
R = ρ L / A
(Where R is resistance, ρ is resistivity, L is length and A is cross sectional area).
Other factors are the plug itself and the amount of power it can draw. Also, factors like QC 3.0 compatibility allow the phone to pull more current at a higher voltage. Phones intelligently decide how much power to draw as well based upon their own tables, the temperature and charge and other properties of the battery.
But, in general, a cable with higher resistance or unable to pull as much power will charge more slowly. Just because a cable is rated for 2A doesn't mean it will achieve this.
To see more detail, I suggest you get a meter that will allow you to measure the precise current and voltage using the same USB plug and different cables.