TL;DR:
In the 1600s, when the Dutch occupied parts of southern Taiwan, the natives, who spoke the Taiwanese Hokkien dialect, called the Dutch rulers the Taioan (大員), meaning "person (people) of authority". At that time, there were no common standard of measurement in Taiwan because the Han descendants from various parts of China brought over different conflicting standards, so the Dutch Taioan enforced a new standard of measurement for length, weight, and area. (These are still in use today, although all official/scientific/education have long since adopted the metric system.)
Since those were the only standard enforced by an authority, it spread quickly and gained adoption among the coastal provinces of China. Eventually, the Chinese people started calling those people living on that island (i.e. Taiwan) who uses the Taioan standards the Taioan people, and the island the Taioan island.
Since Taiwanese Hokkien at that time was just a spoken dialect, the Chinese took the closest Mandarin pronounciation of it and wrote it as "臺灣", which when transliterated into English, becomes "Taiwan".
I don't know about Thailand, so can't comment there.