As Miniman's answer points out, you cannot grapple as an opportunity attack because an opportunity attack does not give you an Attack action. However, your situation doesn't actually call for an opportunity attack. Instead, it sounds like you had readied an action. From Basic Rules page 72:
Sometimes you want to get the jump on a foe or wait for a particular circumstance before you act. To do so, you can take the Ready action on your turn so that you can act later in the round using your reaction.
First, you decide what perceivable circumstance will trigger your reaction. Then, you choose the action you will take in response to that trigger, or you choose to move up to your speed in response to it...
When the trigger occurs, you can either take your reaction right after the trigger finishes or ignore the trigger. Remember that you can take only one reaction per round.
When you ready an action, you declare that you intend to do something out of your turn in response to something specific happening. For example, you can ready an action by saying "If an enemy comes through that door, I will fire an arrow at them." If an enemy does come through the door, you can then immediately use the readied action and shoot them.
Therefore, if you state on your turn, "I want to grapple the gnome if he tries to get past me," and you have not taken another action on your turn, you would be able to grapple the gnome as he moves past you. If the gnome doesn't try to get by you, the action is wasted. You can also choose to ignore the trigger and take an attack of opportunity as your reaction instead.
Keep in mind that you must declare a Ready action on your turn. Ready actions are actions, like attacks or casting spells. If your turn had already passed when you declared you'd grapple the gnome, your DM would be right in ruling that you can only make an attack. However, if you declared it on your turn, and hadn't already attacked or acted, your DM should have allowed you to grab the gnome.
Yes, as long as the grapple is delivered by a melee attack that doesn't require some other specific Action
The sage advice compendium answered a similar question to this one about spell attacks. In part, it talks about monsters making spell attacks as opportunity attacks. The clarification notes that:
A few monsters can make opportunity attacks with melee
spell attacks. Here’s how: certain monsters—including
the banshee, the lich, and the specter—have a melee spell
attack that isn’t delivered by a spell. For example, the banshee’s
Corrupting Touch action is a melee spell attack but
no spell is cast to make it. The banshee can, therefore,
make opportunity attacks with Corrupting Touch.
From this, we can determine that a monster can use any of its melee attack options when it makes an opportunity attack, as long as they don't require some other action to use (like how the grapple or shove attacks in the PHB require the Attack action).
So, the vampire spawn can use its claw attack as an opportunity attack since it's a melee attack that is not mandated to be delivered by some other specific action. The claw attack itself can grapple a target if it hits instead of dealing damage. And since opportunity attacks do not specifically override any on-hit effects from making an attack, the vampire spawn can elect to replace the damage roll with the grapple.
Best Answer
Yes.