And just to point out. That I wrote this long with all these examples only because I found it fun to write about legal matters. And also, that I am no lawyer, and this is one of the tricky cases in law, hence I am not sure it really would go like this, just to my understanding this is about the principle how it generally goes and basis for it, but it varies from country to country. Especially since, as i already mentioned, its a tricky case.
It's a simple case. The person you bought it from had no right to sell it, therefore you didn't get anything for your money and you should demand a refund.
If you buy a car that was stolen and it gets identified then the original owner (or the insurance company who paid out on the claim) will recover the car from you. The first you'll know is that someone will knock on your door to take your car there and then. If you go to court then the judge won't care whether you need the car, because it's someone else's property. All you can do is sue the person who sold it to you, if it was a legitimate car dealer then you will know where to find them and they should have enough money to pay you. If they are dodgy then they will either have disappeared or will declare themselves insolvent when you ask for your refund. Caveat emptor and all that.
I don't believe there are any countries where the law is written in the way you think. However there are countries where laws don't get applied.