The method used to obtain tokens varies slightly between CTR and CNK, and the purple tokens have a different obtain method in both games.
Crash Team Racing
In CTR, players need to get the letters C, T, and R in a race, and come in first place to win a token.
Crash Nitro Kart
In CNK, this is the same, except players need to get the letters C, N, and K instead.
Crash Team Racing Nitro-Fueled
The remake has the same method, also requiring that players collect the letters C, T and R.
Purple tokens are obtained through a different method in both CTR, CNK and Nitro-Fueled. After defeating the boss of a planet/area, the area's battle arena is unlocked, where players need to collect all of the crystals in the arena before time runs out. Doing so awards a purple token. Collecting all these tokens awards the player with a bonus battle arena in CNK.