For Android, you could do something like boot into Recovery, completely format all the partitions (except recovery), and reflash the ROM. If you wanted to be especially paranoid you could adb into it and dd if=/dev/zero the whole thing a time or two and then reflash it. Hell of a lot of work though, and typically would require some kind of rooting or alternative recovery for some of the options.
iOS devices you'd pretty much have to jailbreak to do something like that directly. I have no idea how thorough a restore in iTunes is forensically speaking. Might be good enough.
I'd be somewhat hesitant to resell/donate a mobile device. I tend to keep them around and use them until they're thoroughly used up anyway, so I don't typically have anything left worth selling/donating.
I too have bought a few random computers at thrift stores over the years, and have found enough personal data to make several peoples' lives miserable. Not really my style though; I typically wipe them as a first step. Although I did unexpectedly find an older laptop with a legit activated Windows 8 license on it that I just nuked the previous user account on and kept using, since upgraded to 10. It's still impressive to me the kind of things people leave on computers they're donating. I keep seeing the words "common sense" thrown around in this article, but I'm still surprised more people don't have it.