All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah and that Muhammad is His slave and Messenger.
If you took money that is not yours, then it is incumbent on you to strive in returning this money to the rightful owners; it has become a trust and you are liable to returning it. You are obliged to try to return the money to the rightful owners to the best of your ability.
If you did your best to reach the rightful owners of this money but could not and have lost hope in finding and reaching them, then you may spend this money in charity on their behalf. If you happened to reach them at any time in the future, then you should offer them the choice either to approve your disposal of their money by offering it in charity or to claim their money back. If they choose to claim their money, then you have to give it back and you will still be rewarded for the charity that you offered.
Haashiyat Ar-Rawdh Al-Murbi‘ reads:
"The pawned items of wealth, deposits, and all forms of trust as well as unlawful articles of wealth, such as stolen items or those acquired by force, or things that have been borrowed or entrusted to a person and he does not know the rightful owners; one should give them to the ruler or spend them in charity on behalf of the real owners knowing that he remains liable to returning them to the owners whenever they are identified and reached because by offering this money in charity, he attains two benefits; the current holder of the wealth is cleared of his liability and the rightful owner benefits by having the rewards of the charity dedicated to him..."
Allaah knows best.