Going to gym can cause mixing with women with out proper Hijab and can cause you hearing sinful music. If there are no women at all and no sinful music,b then it is allowed to go to the gym. Headphones cover your ears up to some extent but still you will be able to hear. You must be sure that you are away from listening sinful music.
Wassalam.