Let's say someone bought a used computers which has a copy of a bunch of Bitcoin keypairs. Is he legally allowed to transfer them?
Is this case analogous to finding a pile of cash inside a used bag?
This is going to depend a lot on many surrounding facts. Including where this happens. How you acquired the computer and whether you know who the owner is.
I'm most familiar with the law in Australia (Victoria) where stealing is defined as follows: "A person steals if he dishonestly appropriates property belonging to another with the intention of permanently depriving the other of it." I imagine many common law countries have relatively similar definitions (with important differences for edge cases, of which this is one).
If you see bitcoins as property then your example involves theft. I think most jurisdictions will define bitcoins as a form of property, if they don't there would be all sorts of tax issues. This would be the case in Australia and it would be theft.
To me I don't think this is analogous to finding a pile of cash inside a used bag. I think it is closer to find someone's internet banking username and password inside a bag you purchased. Bitcoins are not physical and the private keys (which is what you would find) merely grant you access to them. Most people would agree that doing anything with the internet banking details would be dishonest.
The difference in my example would be whether destroying the keys would be a crime. It is unlikely to be a problem with internet banking details as there is no expectation this would permanently deprive the person of their property. With bitcoin you don't know if there is a backup so you would at least be recklessly dealing with someone's property.
Buying an old computer with a Bitcoin wallet on it containing BTC would be analogues to buying an old chest of drawers that holds a wallet with some cash in it (and no ID). You might ask the seller about the wallet since it may not have been intended to be sold but, you ask with a copy of a bunch of Bitcoin keypairs.
If you buy an old computer and it happens to have the plans for the greatest world-changing invention since sliced bread on it, can you claim ownership of the plans? You brought the computer which contains the hard disk, which contains the plans so it would seem at first that you could, however, there are at least copyright and intellectual property laws protecting works to consider in that case.
In the case of the keypairs, I would assume that a court would see using them as computer hacking. I won't cite the case in detail for the length of reply needed but; there was a case in Queensland of a boy around ten years ago convicted of computer hacking. He was using the command prompt on a Windows PC and typing net use over a dial-up connection to access publicly and openly shared files on other computers. That was the court's view, that it was computer hacking.
In any case, using the key pairs you would be deliberately taking something that does not belong to you and that you have certainly not purchased with the computer, and that is theft at least.
If it had usernames and passwords for loging in to various websites you would be no more entitled to use those.
When you own the private keys, you own the coins. It's that simple. You would Need the passphrase to the wallet, though.
Since Bitcoin deals in skirting tax laws and is primarily used by shady types I see no reason why anyone would not just claim the bitcoins, after all most governments, corporations and stock market gurus have at one time or another been corrupt or dealt with insider and information.