When a carboxylic acid acts as a nucleoplile, why does it attack through the carbonyl bond? Here's a couple of examples of what I mean. Firstly, in the reaction with thionyl chloride to make a carboxylic acid:



Secondly, in this specific example of a hydroboration reaction:



I don't really understand why you cant attack from the hydroxide group and then proton transfer. Any suggestions?
For both the examples that you mentioned, the carbonyl oxygen has its lone pair localized while the other oxygen's lone pair is delocalized with the double bond. The better nucleophile is the one which has greater electron density.