You can pray in the locker room, if it is permissible, otherwise, you can delay your prayer till you reach home, if you will reach home before midnight.
However, if you were neither able to pray in the locker room, nor able to reach home before midnight, then, you need to cancel your swimming class.