There are 2 types of tickets for the THSR, the "reserved seat" and the "free seating" ticket. Reserved seat tickets are only good for the designated train, but you can book the ticket in advance; free seating tickets are good for the whole day, but can only be bought on the day of the trip. If you hold a reserved seat ticket and missed your train, you will have to return to the ticketing window and buy a new one.
The ticketing windows for the THSR are staffed between the hours of 6 a.m. to 10 p.m., and tickets are sold up up to 5 minutes before the train's scheduled departure. If for some crazy reason you have to take a train that leaves past 10 p.m. (Right now only train #531 leaves after 10 p.m), you can buy from the automatic ticketing machine.
The same rules apply for TRA Zhi-Chiang and Chu-Guang class trains. Tickets are only good for the designated train, and if you missed the train you have to purchase a new ticket. However, I am not sure if this same rule applies for commuter trains.
TRA ticket windows operate at different times at different stations, but in general the operating hours are dictated by the station's train schedule; it opens before the first train and closes after the last train for the day leaves the station. But in some rural stations with little traffic, they may not have a ticketing window, instead you will have to buy from the ticketing machine (too little traffic to justify hiring a ticketing agent).