Praise be to Allah.
If someone receives a delivery of food by mistake, it is not permissible for him to eat it and it does not belong to him, because he did not buy it, and there is no reason to suggest that it now belongs to him, such as it being given to him as a gift. Therefore it remains the property of its owner.
What he must do is return it to the one who delivered it to him: by contacting the delivery company or taking it back to the restaurant. In most cases, the name of the restaurant can be found on the wrapping or container of the food.
If it so happens that it is not possible to return it to the restaurant or to the delivery company, as there is no information available or they do not answer the telephone, then in that case you should give the food in charity to the poor and needy, with the intention that the reward for that should go to the owner. It is also permissible to work out the price of the food, then keep the food and give its price in charity.
Shaykh al-Islam Ibn Taymiyah (may Allah have mercy on him) said: If it is not possible to find the owner of property, then it may be disposed of in the best interests of the Muslims according to the majority of scholars, such as Maalik, Ahmad and others.
So if someone has in his possession something that was seized by force, or borrowed, or left with him for safekeeping or as a pledge, and he has given up hope of finding out who its owners are, he may give it in charity on their behalf, or dispose of it in the best interests of the Muslims, or hand it over to a man of good character who can who can divide it among various causes that serve the Muslims’ interests.
Some of the fuqaha’ said: It should be held indefinitely until it is found out who its owners are.
But the correct view is the first one, because there is no benefit in holding property indefinitely when there is no hope of finding its owner; rather there is the risk that the property may decay or be destroyed, or that evildoers may take it by force.
‘Abdullah ibn Mas‘ood bought a slave woman, then he went into his house to fetch the price, and when he came out he could not find the seller. So he went around looking for poor people and give the price to them in charity, saying: O Allah, it is on behalf of the owner of the slave woman. If he accepts that, all well and good, and if he does not accept it, then it is on my behalf and I will owe the equivalent on the Day of Resurrection.
Similar fatwas were issued by some of the Taabi‘een regarding one who steals from the war booty and repents after the army has dispersed: he should give it in charity on their behalf. The Sahaabah and the Taabi‘een whom it reached approved of this fatwa, such as Mu‘aawiyah and others among the people of Syria." (Majmoo‘ al-Fataawa 29/321).
And Allah knows best.