The lock is a visual representation of Blaine's challenge. You must prove yourself worthy by defeating him in a Pokemon battle before he grants you access to the gym.
It's a common mechanic in Pokemon games to use locked doors or barriers to signify the need to overcome a specific challenge before progressing. In this case, the challenge is defeating Blaine.