At the gym, <something happened>.
I was at the gym when <describe event>.
Being at the gym was <describe feeling>.
While at the gym, <describe event>.
Today, at the gym, I <describe situation>.
He left his wallet at the gym. (used to describe a location)
The cost of food at the gym is expensive. (used to say where something happened).
There are many situations in English, where we use "at the <place>".
If you take away "at the" and you're left with the word "gym", there are more ways to use it as a noun.
The gym was cold and dark.
I was at gym class when the lights went out.
I lost my phone, but it was in the gym.
When a speaker omits "the" before gym it is implied by context.
"Each day at gym, I disliked running."
We know the speaker is in the gymnasium.
We know the speaker is there for some type of class, lesson, or practice.
We know the speaker is using the word gym to mean a location.