Copied from Smashwiki:
Sonic: 6, 10, 10
If you don't want to click the link, those are Sonic's grabs in the soonest they come out. The order is standing, running, and pivot grab respectively. Understand that Ness has more frames from being ground grab-released than everybody else except Lucas, who shares the same amount of frames (how much it is though I forgot, I believe it was 10 frames longer).
Your best bet is to practice it, because you'll need to time it, and it's not exactly that easy when you don't have it down. You should be able to buffer the CG, if you can do that.
To start, I'd say play on a stage that has a wall, or make one. practice getting it down when he can't move. You know you'll be doing it wrong if you have somebody else help you and press the attack button to jab you. If he didn't get a grab off, success.
Slowly work your way to real-time CGing. It didn't help me, but it may help you to go into training mode and slow down time.
In the end, if you really can't do it, you can always do Forward and Down Tilts on Ness/Lucas, they're guaranteed to hit him from a ground-grab-release. Although all of your throws do more damage (I'm not sure if you'll be able to hit with both hits of FTilt, if that's possible, then I take my last sentence back, and the only throw that beats it damage-wise is U-Throw. This is assuming all moves are fresh.), you may get a kill on Ness at a reasonable % if you do it from the very edge of a stage and hit him with a FTilt or perhaps send him at a low angle with the DTilt.