It's pretty easy to trap a non-flying forgotten beast. Not inside a trap, but trap it as in it cannot reach any of your dwarves or escape its situation.
The basic idea is that forgotten beasts consider grates and floor hatches pathable, but upon seeing one, they will attack it and destroy it rather than crossing over.
So you create a cell for the thing somewhere, and make a path that connects from where it currently is to the cell where you want it to end up. Then, you block off all passages leading to your dwarves, except for a single path leading from the other end of the cell into the fortress\common area. Then, you channel out 3 floors in the hallway of that 2nd path and remove the ramps from the side that leads to your fortress, and build 3 grates over the path. Once it's complete, have your military retreat through this path over the grates. The cockroach will surely follow. When he reaches the grates, he will destroy them, leaving him no way into your fort. If you're lucky, he will stand still at this point, and if not, he'll quickly run back into the underground to a point where he was standing at an earlier time. Either way, as soon as he's in the room with the grates and destroys the grates, you need to break back into the underground from behind him and seal off the hallway that led into his cell. Now he's trapped in the cell.
Depending how well you engineer the cell and the paths in and out, you can end up with a FB perfectly where you want him by using this knowledge about how they look for a way into your fort and how they interact with grates, hatches, and ledges. A FB that can't fly will consider a ledge without a ramp as impassable and so once he destroys the grate he's screwed.