Hello lorqrz
Yes, the time of purchase as well as the train’s departure time are both known to the ticket inspector’s control device, and therefore your ticket is marked as invalid when being checked later. @RedBaron correctly explained to you why.
Also, holding the door while purchasing the ticket is not recommended; there are examples in the past where passengers were brought to court and fined with a hefty fine by the authorities as holding the door is considered an official offence, known as “impeding the public transport”.
Next time, simply take the next train. There is a train to Zurich main station literally every 10 minutes. Or, purchase your ticket earlier as memtioned by @Krist; long-distance tickets are valid for the entire day, you could purchase it even the day before.
Kind regards,
Roland