Without permission from the person who is paying for the trash service it is indeed illegal to use someone else's trash can to dump your trash in.
Now if you have permission from the person and they say you can throw your trash in their trash can then it's not illegal.
But if you just go around dumping your trash in peoples trash cans without their permission they can call the police and have you warned or ticketed for illegal trash dumping.
If you continue to dump the trash in their trash cans and they call the police on you again then you can be fined or arrested and spend 90 days to 1 year in jail and sometimes as much as 5 years in prison if it continues.