Laundry detergent is specially designed to have different electrical charges on different parts of the molecule. Each molecule of laundry detergent has a positive charge and a negative charge on it. This helps the laundry detergent clean by giving a spot on the molecule for either a negatively charged particle (dirt or soil) to be attracted to, or a spot on the molecule for a positively charged particle to be attracted to. Either way, the soil or dirt will be attracted to the detergent molecule, and cling there and stay in the water rather than re-depositing on the clothes.
Laundry detergent tends to be alkaline in nature, or having a pH of 7.1-14. This is helpful because most dirt and soils are acidic, which the laundry detergent is able to help neutralize with a basic pH.
PH decreases as water gets hotter. Therefore, hotter water temperature can make the detergent more acidic and thus less able to neutralize soil.
Most detergents were scientifically designed by the manufacturer to do the best job at cleaning clothes that it can. This means it is crucial to follow the manufacturer's directions for optimizing performance. Changing parameters such as wash temperature, or adding wash supplements such as vinegar or baking soda can do a lot to alter the chemistry that the detergent relies upon in order to work.