I don't know exactly when buggy was captured and tossed into Impel Down, but it's a safe bet it happened rather soon after he dared return to the Grand Line. Buggy is not strong, there's no getting around it. Before Luffy around, he was running around pointlessly. Of every notable person there (Luffy, Bon Kurei, Mr. 3, Ivankov, etc.) he was the only one that couldn't defeat the Blugori. He's not too smart, either, and has laughably bad instincts. But, given the right tools and opportunities, he is cunning. His Muggy Dama is pretty powerful, too, as was demonstrated first hand on one of Impel Down's demon guards (even if it didn't work). One could say Buggy's greatest strengths are 'luck' and 'timing'. Because he was in the right place, at the right time, with the right people to protect him, he managed, beyond all odds, to make it big during the war at Marinford.
But this thread isn't about how strong Buggy is. Having thought about it, I have to revise my previous statement; Shanks probably does know Raftel's location, and he may indeed have seen One Piece, whatever it is, because if I remember correctly, when the Roger pirates disbanded in Loguetown, Shanks was there. It was probably then that he decided to form his own crew.