Learning Koopman Dynamics for Safe Legged Locomotion with Reinforcement Learning-based Controller