In SHM, acceleration is always in the opposite direction of the oscillating particle.But, in the case of a pendulum, when the bob is, at first, set free, it's displacement is towards the acceleration before reaching the equilibrium position. So why is the acceleration of the oscillating bob in the direction of its displacement?
You are right in saying that in SHM (Simple Harmonic Motion) the acceleration is opposite to the displacement.
Suppose you have a pendulum of some mass M hanging from a string as shown below.
Here A is the mean position of the bob of the pendelum.
When the bob of the pendelum was at position A then the force of gravity was acting downwards and there was so sideways component of force on the pendelum.
When you displaced it towards the position "B" from "A" the displacement of the particle is from left to right (A to B or from mean position to extreme position)
But The force of gravity still acts downwards and when you break it into its components then one of the components mgsin(θ) acts in a direction that tries to bring the bob back to mean position i.e Force on the bob acts from right to left or from "B" to "A"
Since from newton's second law
F = ma
a = F/m
From the above law we can see that if Force acts from right to left then so does the acceleration.
Thus acceleration of the particle is towards the mean position (right to left or from "B" to "A") but your displacement was away from the mean position i.e from "A" to "B"
Hence acceleration and displacements have opposite directions. I hope I've cleared your confusion.
P.S If by displacement you mean where the particle wants to move now then Its clear that it wants to move towards A and the acceleration is also towards A, So in this sense they are in same direction But then the particle passes position A and it going to the other extreme end then again component of gravity acts towards A and so again acceleration and displacement are in opposite directions