Acyl chlorides can be prepared by reacting carboxylic acids with thionyl chloride (SOCl2), phosphorous trichloride (PCl3) or phosphorous pentachloride (PCl5):

In the bases of this transformation is the conversion of the OH group into a good leaving.
For example, thionyl chloride reacts with carboxylic acids forming a highly reactive intermediate capable of losing excellent leaving groups HCl and SO2 upon a nucleophilic addition of a chloride ion (recall the reaction of alcohols with thionyl chloride):

The arrow in the first step can also start from a lone pair of the double-bonded oxygen of the carbonyl:

And you may ask – why not from the oxygen of the other oxygen? Can the hydroxyl group attack the thionyl chloride instead of the carbonyl oxygen?
This question has the same explanation as the selective protonation of the carbonyl oxygen in the Fischer esterification or, in general, its stronger Lewis base character.
The lone pairs on the hydroxyl can serve a Lewis base but the intermediate forming in this case is not resonance-stabilized while the positively charged carbonyl oxygen is resonance-stabilized:

Need some good practice on the reactions of carboxylic acids and their derivatives?
Check this 45-question, Multiple-Choice Quiz with a 50-min Video Solution covering the reactions of acids, esters, lactones, amides, acid chlorides and etc.
Carboxylic Acids and Their Derivatives Quiz
Check Also
- Preparation of Carboxylic Acids
- Naming Carboxylic Acids
- Naming Nitriles
- Naming Esters
- Naming Carboxylic Acid Derivatives – Practice Problems
- Fischer Esterification
- Ester Hydrolysis by Acid and Base-Catalyzed Hydrolysis
- What is Transesterification?
- Esters Reaction with Amines – The Aminolysis Mechanism
- Ester Reactions Summary and Practice Problems
- Preparation of Acyl (Acid) Chlorides (ROCl)
- Reactions of Acid Chlorides (ROCl) with Nucleophiles
- R2CuLi Organocuprates – Gilman Reagent
- Reaction of Acyl Chlorides with Grignard and Gilman (Organocuprate) Reagents
- Reduction of Acyl Chlorides by LiAlH4, NaBH4, and LiAl(OtBu)3H
- Preparation and Reaction Mechanism of Carboxylic Anhydrides
- Amides – Structure and Reactivity
- Naming Amides
- Amides Hydrolysis: Acid and Base-Catalyzed Mechanism
- Amide Dehydration Mechanism by SOCl2, POCl3, and P2O5
- Amide Reduction Mechanism by LiAlH4
- Reduction of Amides to Amines and Aldehydes
- Amides Preparation and Reactions Summary
- Amides from Carboxylic Acids-DCC and EDC Coupling
- The Mechanism of Nitrile Hydrolysis To Carboxylic Acid
- Nitrile Reduction Mechanism with LiAlH4 and DIBAL to Amine or Aldehyde
- The Mechanism of Grignard and Organolithium Reactions with Nitriles
- The Reactions of Nitriles
- Converting Nitriles to Amides
- Carboxylic Acids to Ketones
- Esters to Ketones
- Carboxylic Acids and Their Derivatives Practice Problems
- Carboxylic Acids and Their Derivatives Quiz
- Reactions Map of Carboxylic Acid Derivatives