This is theft. While theft is defined in different ways in different places, the heartland of theft is "larceny" which involves knowingly taking property without permission of the owner, with an intent to permanently deprive the owner of the property taken.
In general, one of the defining qualities of something that is "property" is that it can't be transferred without the permission of the owner, except in narrowly defined circumstances where the government authorizes a taking.
In a very different but analogous context, if a lawyer takes money held in trust for a client out of the client's trust account with the lawyer, without a valid legal basis for doing so, even if the lawyer intends to and does replace the funds in the trust account later, the lawyer is guilty of a crime.
Unintentional Conversion Compared
If you accidentally and unknowingly take someone else's property, for example, taking the wrong coat from a coat rack, or taking the wrong umbrella, and that item is later destroyed, you have committed the civil wrong (a.k.a. the tort) of conversion, but you haven't committed a crime. Crime usually (but not always) involves acts committed with a bad intent.
But taking someone else's property on purpose, without their permission, is the crime of theft and not just a tort.
Implied Consent To A Purchase Compared
The situation would be different, however, if there is implied permission to purchase the item taken from the person who owns it.
For example, suppose you walk into a convenience store which sells 20 euro candy bars, but there is no one available to sell it to you because the sole employee of the store is hung over and vomiting in the store's toilet. If you take the candy bar and leave a 20 euro bill at the cash register, you have not committed theft, because in that context, the owner of the property has implicitly consented to sell the candy bar to any member of the general public who wants to buy it for the stated price.
Similarly, this is why buying candy from a vending machine isn't theft.
Abandonment Compared
Also, it is important to distinguish property that has been abandoned by the owner, to which a "finder's keepers" rule generally applies, to property which there is no indication that the owner intended to abandon.
So, if someone throws something in the trash, or simply leaves what would generally be thought to be trash in public, like a bag of dog poop, that would not generally be theft, since a reasonable person would assume that the property had been abandoned and no longer had an owner.