Theory of coherent generation and detection of THz acoustic phonons using optical microcavities