Benzenesulfonyl chloride dehydration of an amide to give nitrile
One key detail is that this reaction is performed in the presence of base. Typically pyridine is the solvent. Amides are nucleophilic at oxygen, explained by the resonance structure shown. Displacement of chloride by the amide oxygen gives the O-sulfonylated intermediate. After neutralization, the O-sulfonylimidate is set up for an E2 elimination across the C-N bond to give the nitrile.



In addition to sulfonyl chlorides, $\ce{P4O10}$ and $\ce{POCl3}$ are common reagents for this reaction. In general, the reagent should be electrophilic and be able to act as a leaving group.