Im pretty sure Locke had it when they first crashed because sometime in season 1 he lends it to Sayid and Sayid maoni on how it doesn't point properly. Then he gets it back somehow and during the time jumping he gave it to Richard. Somewhere in there Locke told Richard to come and see him when he was a child - and there was the scene when Richard took all those items to kid-locke, the compass being one of them. Then in the last episode Richard still had the compass but i think he gave it to leg-wound locke. I can't remember back to the actual episode where that scene happened. My answer might just be confusing....or wrong. It's a time travel mindfuck.