First of all, depends on the theropod in question, they aren't that similar across the ranks in that regard. Some had more flexible necks than others. And of course it depends on what angle the opponent would be relative to the theropod.
So rather than giving you an overgeneralized answer to that question, here’s a very helpful visualisation from Snively et al. 2013:
palaeo-electronica.org/content…Shown (3) is the maximum lateral range of motion of the head and neck of
Allosaurus.
A couple of things to note: Of course
Allosaurus is considered one of the large theropods with a rather high degree of cervical flexibility. I don’t know much about Megalosaurs in this regard. A derived tyrannosauroid would almost certainly be less flexible, but of course it would also have a shorter neck to make up for that, which would make grappling it even more difficult.
As you see the individual joints, including the craniocervical articulation, aren’t all that flexible, but if you add up the angles over several you end up able to flex that neck quite a bit rather quickly. So it’s very important to take into consideration where that hypothetical grappling animal has its hold on the neck, and how much of its length is still free to move. That’s of course also relevant because grappling more anteriorly would give the grappler much better leverage and make escaling its grasp much more difficult.
So perhaps theropod flexibility was sufficient for what you describe, perhaps not, depending on where the attacker is standing compared to the theropod and what theropod we are talking about.
As for shaking vigorously, there are certainly theropods I could see doing that, though of course the neck is a vulnerable region and doing so would be risky. But again, depending on the attacker I suppose it could work in some cases.