This was answered in PoA; Sirus arrived at the Potter residence, and asked for Hagrid to give Harry to him. When told that Dumbledore said Hagrid was to take Harry to the Dursely's, he told Hagrid to take the bike, as he 'wouldn't be needing it anymore.' Sirus wasn't in prison at that point; he went from there to the 'duel' with Peter, and THEN was taken to prison.
“I met him!” growled Hagrid. “I musta bin the last ter see him before he killed all them people! It was me what rescued Harry from Lily an’ James’s house after they was killed! Jus’ got him outta the ruins, poor little thing, with a great slash across his forehead, an’ his parents dead … an’ Sirius Black turns up, on that flyin’ motorbike he used ter ride. Never occurred ter me what he was doin’ there. I didn’ know he’d bin Lily an’ James’s Secret-Keeper. Thought he’d jus’ heard the news o’ You-Know-Who’s attack an’ come ter see what he could do. White an’ shakin’, he was. An’ yeh know what I did? I COMFORTED THE MURDERIN’ TRAITOR!” Hagrid roared.
“Hagrid, please!” said Professor McGonagall. “Keep your voice down!”
“How was I ter know he wasn’ upset abou’ Lily an’ James? It was You-Know-Who he cared abou’! An’ then he says, ‘Give Harry ter me, Hagrid, I’m his godfather, I’ll look after him —’ Ha! But I’d had me orders from Dumbledore, an’ I told Black no, Dumbledore said Harry was ter go ter his aunt an’ uncle’s. Black argued, but in the end he gave in. Told me ter take his motorbike ter get Harry there. ‘I won’t need it anymore,’ he says.
“I shoulda known there was somethin’ fishy goin’ on then. He loved that motorbike, what was he givin’ it ter me for? Why wouldn’ he need it anymore? Fact was, it was too easy ter trace. Dumbledore knew he’d bin the Potters’ Secret-Keeper. Black knew he was goin’ ter have ter run fer it that night, knew it was a matter o’ hours before the Ministry was after him.